#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define ll long long
const int N = 1e5 + 5;
const ll inf = 1e18;
long long n, k, x[N], y[N], cnt1, cnt2, m1, m2, ans = inf, b1, b2, s;
vector<long long> v;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for(ll i = 1; i * i <= n; ++i){
if(n % i == 0){
v.pb(i);
if(i != n / i) v.pb(n / i);
}
}
for(ll i = 1, x1, y1; i <= k; ++i){
cin >> x[i] >> y[i];
cin >> x1 >> y1;
}
for(auto to : v){
if(to == n) continue;
cnt1 = 0;
cnt2 = 0;
for(ll i = 1; i <= k; ++i){
b1 = (x[i] + to - 1) / to;
b2 = (y[i] + to - 1) / to;
if(b1 % 2) {
if(b2 % 2) cnt1++;
else cnt2++;
}
else {
if(b2 % 2) cnt2++;
else cnt1++;
}
}
// cout << to << ' ' << cnt1 << ' ' << cnt2 << '\n';
s = n / to;
// cout << s << '\n';
m1 = (s + 1) / 2 * ((s + 1) / 2) + (s / 2) * (s / 2);
m2 = s * s - m1;
// cout << m1 << ' ' << m2 << '\n';
m1 *= to * to;
m2 *= to * to;
// cout << m1 << ' ' << m2 << '\n';
ans = min(ans, min(m1 - cnt1 + cnt2, m2 - cnt2 + cnt1));
// cout << m1 - cnt1 + cnt2 << '\n' << m2 - cnt2 + cnt1 << '\n';
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1296 KB |
Output is correct |
2 |
Correct |
5 ms |
588 KB |
Output is correct |
3 |
Correct |
13 ms |
984 KB |
Output is correct |
4 |
Correct |
13 ms |
1100 KB |
Output is correct |
5 |
Correct |
16 ms |
1252 KB |
Output is correct |
6 |
Correct |
13 ms |
972 KB |
Output is correct |
7 |
Correct |
4 ms |
460 KB |
Output is correct |
8 |
Correct |
11 ms |
924 KB |
Output is correct |
9 |
Correct |
31 ms |
1724 KB |
Output is correct |
10 |
Correct |
23 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
7 ms |
716 KB |
Output is correct |
17 |
Correct |
24 ms |
1612 KB |
Output is correct |
18 |
Correct |
26 ms |
1788 KB |
Output is correct |
19 |
Correct |
59 ms |
1700 KB |
Output is correct |
20 |
Correct |
65 ms |
1740 KB |
Output is correct |
21 |
Correct |
21 ms |
1484 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
16 ms |
896 KB |
Output is correct |
24 |
Correct |
27 ms |
1640 KB |
Output is correct |
25 |
Correct |
5 ms |
332 KB |
Output is correct |
26 |
Correct |
17 ms |
1100 KB |
Output is correct |
27 |
Correct |
26 ms |
1292 KB |
Output is correct |
28 |
Correct |
27 ms |
1796 KB |
Output is correct |
29 |
Correct |
8 ms |
844 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1296 KB |
Output is correct |
2 |
Correct |
5 ms |
588 KB |
Output is correct |
3 |
Correct |
13 ms |
984 KB |
Output is correct |
4 |
Correct |
13 ms |
1100 KB |
Output is correct |
5 |
Correct |
16 ms |
1252 KB |
Output is correct |
6 |
Correct |
13 ms |
972 KB |
Output is correct |
7 |
Correct |
4 ms |
460 KB |
Output is correct |
8 |
Correct |
11 ms |
924 KB |
Output is correct |
9 |
Correct |
31 ms |
1724 KB |
Output is correct |
10 |
Correct |
23 ms |
1100 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
7 ms |
716 KB |
Output is correct |
27 |
Correct |
24 ms |
1612 KB |
Output is correct |
28 |
Correct |
26 ms |
1788 KB |
Output is correct |
29 |
Correct |
59 ms |
1700 KB |
Output is correct |
30 |
Correct |
65 ms |
1740 KB |
Output is correct |
31 |
Correct |
21 ms |
1484 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
16 ms |
896 KB |
Output is correct |
34 |
Correct |
27 ms |
1640 KB |
Output is correct |
35 |
Correct |
5 ms |
332 KB |
Output is correct |
36 |
Correct |
17 ms |
1100 KB |
Output is correct |
37 |
Correct |
26 ms |
1292 KB |
Output is correct |
38 |
Correct |
27 ms |
1796 KB |
Output is correct |
39 |
Correct |
8 ms |
844 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
58 ms |
3576 KB |
Output is correct |
42 |
Correct |
35 ms |
4000 KB |
Output is correct |
43 |
Correct |
41 ms |
3580 KB |
Output is correct |
44 |
Correct |
31 ms |
3864 KB |
Output is correct |
45 |
Correct |
32 ms |
4164 KB |
Output is correct |
46 |
Correct |
69 ms |
3984 KB |
Output is correct |
47 |
Correct |
27 ms |
3692 KB |
Output is correct |
48 |
Correct |
36 ms |
3652 KB |
Output is correct |
49 |
Correct |
28 ms |
3524 KB |
Output is correct |
50 |
Correct |
237 ms |
3892 KB |
Output is correct |
51 |
Correct |
251 ms |
4132 KB |
Output is correct |
52 |
Correct |
229 ms |
3780 KB |
Output is correct |
53 |
Correct |
253 ms |
4108 KB |
Output is correct |
54 |
Correct |
244 ms |
3824 KB |
Output is correct |
55 |
Correct |
251 ms |
4244 KB |
Output is correct |
56 |
Correct |
244 ms |
3716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
20 ms |
1296 KB |
Output is correct |
10 |
Correct |
5 ms |
588 KB |
Output is correct |
11 |
Correct |
13 ms |
984 KB |
Output is correct |
12 |
Correct |
13 ms |
1100 KB |
Output is correct |
13 |
Correct |
16 ms |
1252 KB |
Output is correct |
14 |
Correct |
13 ms |
972 KB |
Output is correct |
15 |
Correct |
4 ms |
460 KB |
Output is correct |
16 |
Correct |
11 ms |
924 KB |
Output is correct |
17 |
Correct |
31 ms |
1724 KB |
Output is correct |
18 |
Correct |
23 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
0 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
7 ms |
716 KB |
Output is correct |
35 |
Correct |
24 ms |
1612 KB |
Output is correct |
36 |
Correct |
26 ms |
1788 KB |
Output is correct |
37 |
Correct |
59 ms |
1700 KB |
Output is correct |
38 |
Correct |
65 ms |
1740 KB |
Output is correct |
39 |
Correct |
21 ms |
1484 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
16 ms |
896 KB |
Output is correct |
42 |
Correct |
27 ms |
1640 KB |
Output is correct |
43 |
Correct |
5 ms |
332 KB |
Output is correct |
44 |
Correct |
17 ms |
1100 KB |
Output is correct |
45 |
Correct |
26 ms |
1292 KB |
Output is correct |
46 |
Correct |
27 ms |
1796 KB |
Output is correct |
47 |
Correct |
8 ms |
844 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
58 ms |
3576 KB |
Output is correct |
50 |
Correct |
35 ms |
4000 KB |
Output is correct |
51 |
Correct |
41 ms |
3580 KB |
Output is correct |
52 |
Correct |
31 ms |
3864 KB |
Output is correct |
53 |
Correct |
32 ms |
4164 KB |
Output is correct |
54 |
Correct |
69 ms |
3984 KB |
Output is correct |
55 |
Correct |
27 ms |
3692 KB |
Output is correct |
56 |
Correct |
36 ms |
3652 KB |
Output is correct |
57 |
Correct |
28 ms |
3524 KB |
Output is correct |
58 |
Correct |
237 ms |
3892 KB |
Output is correct |
59 |
Correct |
251 ms |
4132 KB |
Output is correct |
60 |
Correct |
229 ms |
3780 KB |
Output is correct |
61 |
Correct |
253 ms |
4108 KB |
Output is correct |
62 |
Correct |
244 ms |
3824 KB |
Output is correct |
63 |
Correct |
251 ms |
4244 KB |
Output is correct |
64 |
Correct |
244 ms |
3716 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Incorrect |
0 ms |
316 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |