#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#define fi first
#define se second
#define ll long long
using namespace std;
const int N = 2e5 + 7;
const int M = 23;
const int mod = 998244353;
ll n,k;
ll A[N];
ll B[N];
ll C[N];
ll D[N];
void solve1()
{
cin >> n >> k;
vector < ll > div;
for( int i = 1; i < n; i++ ){
if( n % i == 0 )div.push_back(i);
}
for( int i = 0; i < k; i++ ){
cin >> A[i] >> B[i] >> C[i] >> D[i];
}
ll ans = 1e14;
for( int i = 0; i < (int)div.size(); i++ ){
ll nn = n / div[i];
ll B1 = (nn + 1) / 2;
ll B2 = nn / 2;
B1 *= div[i] * div[i];
B2 *= div[i] * div[i];
B1 *= (nn + 1) / 2;
B2 *= nn / 2;
B1 += B2;
ll B3 = (nn) / 2;
ll B4 = (nn + 1) / 2;
B3 *= div[i] * div[i];
B4 *= div[i] * div[i];
B3 *= (nn + 1) / 2;
B4 *= (nn) / 2;
B3 += B4;
vector < ll > w(k , 0);
vector < ll > b(k , 0);
for( int j = 0; j < k; j++ ){
//ll x = f(C[j] , D[j] , div[i]) - f(C[j] , B[j] - 1 , div[i]) -
//f(A[j] - 1, D[j] , div[i]) + f(A[j] - 1 , B[j] - 1 , div[i]);
//ll y = (C[j] - A[j]) * (D[j] - B[j]);
ll x = 0;
ll y = 1;
if( (A[j] - 1) / div[i] % 2 == 0 && (B[j] - 1) / div[i] % 2 == 0 ){
x = 1;
}
if( (A[j] - 1) / div[i] % 2 == 1 && (B[j] - 1) / div[i] % 2 == 1 ){
x = 1;
}
w[j] = y - x;
b[j] = x;
}
ll x = 0;
ll y = 0;
//cout << B1 << " " << B3 << " ";
for( int j = 0; j < k; j++ ){
B1 -= b[j];
x += 1 - b[j];
y += b[j];
B3 -= 1 - b[j];
}
//cout << B1 + x << " " << B3 + y << " " << div[i] << "\n";
ans = min(ans , B1 + x);
ans = min(ans , B3 + y);
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen( "input.txt" , "r" , stdin );
//freopen( "output.txt" , "w" , stdout );
int cghf = 1;//cin >> cghf;
while( cghf-- ){
solve1();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
420 KB |
Output is correct |
5 |
Correct |
3 ms |
380 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3704 KB |
Output is correct |
2 |
Correct |
10 ms |
1448 KB |
Output is correct |
3 |
Correct |
22 ms |
2552 KB |
Output is correct |
4 |
Correct |
23 ms |
2924 KB |
Output is correct |
5 |
Correct |
30 ms |
3448 KB |
Output is correct |
6 |
Correct |
20 ms |
2424 KB |
Output is correct |
7 |
Correct |
6 ms |
888 KB |
Output is correct |
8 |
Correct |
20 ms |
2296 KB |
Output is correct |
9 |
Correct |
47 ms |
5072 KB |
Output is correct |
10 |
Correct |
27 ms |
3064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
420 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
504 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
420 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
504 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
17 ms |
2168 KB |
Output is correct |
17 |
Correct |
37 ms |
4652 KB |
Output is correct |
18 |
Correct |
52 ms |
5604 KB |
Output is correct |
19 |
Correct |
154 ms |
5220 KB |
Output is correct |
20 |
Correct |
179 ms |
5692 KB |
Output is correct |
21 |
Correct |
36 ms |
4728 KB |
Output is correct |
22 |
Correct |
3 ms |
380 KB |
Output is correct |
23 |
Correct |
32 ms |
2876 KB |
Output is correct |
24 |
Correct |
48 ms |
5112 KB |
Output is correct |
25 |
Correct |
8 ms |
888 KB |
Output is correct |
26 |
Correct |
31 ms |
3584 KB |
Output is correct |
27 |
Correct |
43 ms |
4088 KB |
Output is correct |
28 |
Correct |
52 ms |
5432 KB |
Output is correct |
29 |
Correct |
16 ms |
2424 KB |
Output is correct |
30 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3704 KB |
Output is correct |
2 |
Correct |
10 ms |
1448 KB |
Output is correct |
3 |
Correct |
22 ms |
2552 KB |
Output is correct |
4 |
Correct |
23 ms |
2924 KB |
Output is correct |
5 |
Correct |
30 ms |
3448 KB |
Output is correct |
6 |
Correct |
20 ms |
2424 KB |
Output is correct |
7 |
Correct |
6 ms |
888 KB |
Output is correct |
8 |
Correct |
20 ms |
2296 KB |
Output is correct |
9 |
Correct |
47 ms |
5072 KB |
Output is correct |
10 |
Correct |
27 ms |
3064 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
420 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
17 ms |
2168 KB |
Output is correct |
27 |
Correct |
37 ms |
4652 KB |
Output is correct |
28 |
Correct |
52 ms |
5604 KB |
Output is correct |
29 |
Correct |
154 ms |
5220 KB |
Output is correct |
30 |
Correct |
179 ms |
5692 KB |
Output is correct |
31 |
Correct |
36 ms |
4728 KB |
Output is correct |
32 |
Correct |
3 ms |
380 KB |
Output is correct |
33 |
Correct |
32 ms |
2876 KB |
Output is correct |
34 |
Correct |
48 ms |
5112 KB |
Output is correct |
35 |
Correct |
8 ms |
888 KB |
Output is correct |
36 |
Correct |
31 ms |
3584 KB |
Output is correct |
37 |
Correct |
43 ms |
4088 KB |
Output is correct |
38 |
Correct |
52 ms |
5432 KB |
Output is correct |
39 |
Correct |
16 ms |
2424 KB |
Output is correct |
40 |
Correct |
4 ms |
504 KB |
Output is correct |
41 |
Correct |
135 ms |
4796 KB |
Output is correct |
42 |
Correct |
58 ms |
7084 KB |
Output is correct |
43 |
Correct |
85 ms |
6292 KB |
Output is correct |
44 |
Correct |
57 ms |
6776 KB |
Output is correct |
45 |
Correct |
54 ms |
7288 KB |
Output is correct |
46 |
Correct |
159 ms |
7036 KB |
Output is correct |
47 |
Correct |
46 ms |
6368 KB |
Output is correct |
48 |
Correct |
70 ms |
6588 KB |
Output is correct |
49 |
Correct |
53 ms |
6348 KB |
Output is correct |
50 |
Correct |
629 ms |
7028 KB |
Output is correct |
51 |
Correct |
675 ms |
7356 KB |
Output is correct |
52 |
Correct |
621 ms |
7048 KB |
Output is correct |
53 |
Correct |
667 ms |
7404 KB |
Output is correct |
54 |
Correct |
614 ms |
6724 KB |
Output is correct |
55 |
Correct |
693 ms |
7804 KB |
Output is correct |
56 |
Correct |
602 ms |
6772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
420 KB |
Output is correct |
5 |
Correct |
3 ms |
380 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
33 ms |
3704 KB |
Output is correct |
10 |
Correct |
10 ms |
1448 KB |
Output is correct |
11 |
Correct |
22 ms |
2552 KB |
Output is correct |
12 |
Correct |
23 ms |
2924 KB |
Output is correct |
13 |
Correct |
30 ms |
3448 KB |
Output is correct |
14 |
Correct |
20 ms |
2424 KB |
Output is correct |
15 |
Correct |
6 ms |
888 KB |
Output is correct |
16 |
Correct |
20 ms |
2296 KB |
Output is correct |
17 |
Correct |
47 ms |
5072 KB |
Output is correct |
18 |
Correct |
27 ms |
3064 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
420 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
3 ms |
376 KB |
Output is correct |
32 |
Correct |
3 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
17 ms |
2168 KB |
Output is correct |
35 |
Correct |
37 ms |
4652 KB |
Output is correct |
36 |
Correct |
52 ms |
5604 KB |
Output is correct |
37 |
Correct |
154 ms |
5220 KB |
Output is correct |
38 |
Correct |
179 ms |
5692 KB |
Output is correct |
39 |
Correct |
36 ms |
4728 KB |
Output is correct |
40 |
Correct |
3 ms |
380 KB |
Output is correct |
41 |
Correct |
32 ms |
2876 KB |
Output is correct |
42 |
Correct |
48 ms |
5112 KB |
Output is correct |
43 |
Correct |
8 ms |
888 KB |
Output is correct |
44 |
Correct |
31 ms |
3584 KB |
Output is correct |
45 |
Correct |
43 ms |
4088 KB |
Output is correct |
46 |
Correct |
52 ms |
5432 KB |
Output is correct |
47 |
Correct |
16 ms |
2424 KB |
Output is correct |
48 |
Correct |
4 ms |
504 KB |
Output is correct |
49 |
Correct |
135 ms |
4796 KB |
Output is correct |
50 |
Correct |
58 ms |
7084 KB |
Output is correct |
51 |
Correct |
85 ms |
6292 KB |
Output is correct |
52 |
Correct |
57 ms |
6776 KB |
Output is correct |
53 |
Correct |
54 ms |
7288 KB |
Output is correct |
54 |
Correct |
159 ms |
7036 KB |
Output is correct |
55 |
Correct |
46 ms |
6368 KB |
Output is correct |
56 |
Correct |
70 ms |
6588 KB |
Output is correct |
57 |
Correct |
53 ms |
6348 KB |
Output is correct |
58 |
Correct |
629 ms |
7028 KB |
Output is correct |
59 |
Correct |
675 ms |
7356 KB |
Output is correct |
60 |
Correct |
621 ms |
7048 KB |
Output is correct |
61 |
Correct |
667 ms |
7404 KB |
Output is correct |
62 |
Correct |
614 ms |
6724 KB |
Output is correct |
63 |
Correct |
693 ms |
7804 KB |
Output is correct |
64 |
Correct |
602 ms |
6772 KB |
Output is correct |
65 |
Correct |
2 ms |
376 KB |
Output is correct |
66 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |