/** @BY_KUTBILIM **/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).end()
const int inf = (int)1e9+7;
int main(){
ios_base::sync_with_stdio(false);
cin.tie();
int k;
ll n;
cin >> n >> k;
int x1[k], x2[k], y1[k], y2[k];
vector<ll> div;
div.pb(1);
for(int i = 2; i <= sqrt(n); i++){
if(n % i == 0){
div.pb(i);
if(i != n / i){
div.pb(n/i);
}
}
}
sort(all(div));
vector<ll> cnt1((int)div.size(), 0), cnt0((int)div.size(), 0);
for(int i = 0; i < k; i++){
cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
x1[i]--;
y1[i]--;
for(int j = 0; j < (int)div.size(); j++){
if((x1[i] / div[j] + y1[i] / div[j]) % 2 == 0)cnt0[j]++;
else cnt1[j]++;
}
}
ll ans = n * n;
for(int i = 0; i < (int)div.size(); i++){
ans = min({ans,
n * n / (div[i] * div[i]) / 2ll * (div[i] * div[i]) + (div[i] * div[i]) - cnt0[i] + cnt1[i],
n * n / (div[i] * div[i]) / 2ll * (div[i] * div[i]) - cnt1[i] + cnt0[i]});
}
cout << ans;
return 0;
}
/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1260 KB |
Output is correct |
2 |
Correct |
7 ms |
620 KB |
Output is correct |
3 |
Correct |
16 ms |
1004 KB |
Output is correct |
4 |
Correct |
17 ms |
1004 KB |
Output is correct |
5 |
Correct |
21 ms |
1132 KB |
Output is correct |
6 |
Correct |
19 ms |
1004 KB |
Output is correct |
7 |
Correct |
4 ms |
640 KB |
Output is correct |
8 |
Correct |
14 ms |
876 KB |
Output is correct |
9 |
Correct |
36 ms |
1772 KB |
Output is correct |
10 |
Correct |
19 ms |
1132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
12 ms |
748 KB |
Output is correct |
17 |
Correct |
28 ms |
1644 KB |
Output is correct |
18 |
Correct |
42 ms |
1864 KB |
Output is correct |
19 |
Correct |
70 ms |
1644 KB |
Output is correct |
20 |
Correct |
75 ms |
2028 KB |
Output is correct |
21 |
Correct |
27 ms |
1644 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
25 ms |
1024 KB |
Output is correct |
24 |
Correct |
33 ms |
1772 KB |
Output is correct |
25 |
Correct |
4 ms |
492 KB |
Output is correct |
26 |
Correct |
21 ms |
1260 KB |
Output is correct |
27 |
Correct |
28 ms |
1516 KB |
Output is correct |
28 |
Correct |
35 ms |
1772 KB |
Output is correct |
29 |
Correct |
11 ms |
876 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1260 KB |
Output is correct |
2 |
Correct |
7 ms |
620 KB |
Output is correct |
3 |
Correct |
16 ms |
1004 KB |
Output is correct |
4 |
Correct |
17 ms |
1004 KB |
Output is correct |
5 |
Correct |
21 ms |
1132 KB |
Output is correct |
6 |
Correct |
19 ms |
1004 KB |
Output is correct |
7 |
Correct |
4 ms |
640 KB |
Output is correct |
8 |
Correct |
14 ms |
876 KB |
Output is correct |
9 |
Correct |
36 ms |
1772 KB |
Output is correct |
10 |
Correct |
19 ms |
1132 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
12 ms |
748 KB |
Output is correct |
27 |
Correct |
28 ms |
1644 KB |
Output is correct |
28 |
Correct |
42 ms |
1864 KB |
Output is correct |
29 |
Correct |
70 ms |
1644 KB |
Output is correct |
30 |
Correct |
75 ms |
2028 KB |
Output is correct |
31 |
Correct |
27 ms |
1644 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
25 ms |
1024 KB |
Output is correct |
34 |
Correct |
33 ms |
1772 KB |
Output is correct |
35 |
Correct |
4 ms |
492 KB |
Output is correct |
36 |
Correct |
21 ms |
1260 KB |
Output is correct |
37 |
Correct |
28 ms |
1516 KB |
Output is correct |
38 |
Correct |
35 ms |
1772 KB |
Output is correct |
39 |
Correct |
11 ms |
876 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
66 ms |
1772 KB |
Output is correct |
42 |
Correct |
40 ms |
1804 KB |
Output is correct |
43 |
Correct |
47 ms |
1644 KB |
Output is correct |
44 |
Correct |
47 ms |
1772 KB |
Output is correct |
45 |
Correct |
38 ms |
1900 KB |
Output is correct |
46 |
Correct |
71 ms |
1772 KB |
Output is correct |
47 |
Correct |
33 ms |
1644 KB |
Output is correct |
48 |
Correct |
43 ms |
1644 KB |
Output is correct |
49 |
Correct |
36 ms |
1644 KB |
Output is correct |
50 |
Correct |
235 ms |
1900 KB |
Output is correct |
51 |
Correct |
251 ms |
2156 KB |
Output is correct |
52 |
Correct |
232 ms |
1772 KB |
Output is correct |
53 |
Correct |
260 ms |
1900 KB |
Output is correct |
54 |
Correct |
229 ms |
1772 KB |
Output is correct |
55 |
Correct |
256 ms |
1900 KB |
Output is correct |
56 |
Correct |
224 ms |
1772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
24 ms |
1260 KB |
Output is correct |
10 |
Correct |
7 ms |
620 KB |
Output is correct |
11 |
Correct |
16 ms |
1004 KB |
Output is correct |
12 |
Correct |
17 ms |
1004 KB |
Output is correct |
13 |
Correct |
21 ms |
1132 KB |
Output is correct |
14 |
Correct |
19 ms |
1004 KB |
Output is correct |
15 |
Correct |
4 ms |
640 KB |
Output is correct |
16 |
Correct |
14 ms |
876 KB |
Output is correct |
17 |
Correct |
36 ms |
1772 KB |
Output is correct |
18 |
Correct |
19 ms |
1132 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
12 ms |
748 KB |
Output is correct |
35 |
Correct |
28 ms |
1644 KB |
Output is correct |
36 |
Correct |
42 ms |
1864 KB |
Output is correct |
37 |
Correct |
70 ms |
1644 KB |
Output is correct |
38 |
Correct |
75 ms |
2028 KB |
Output is correct |
39 |
Correct |
27 ms |
1644 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
25 ms |
1024 KB |
Output is correct |
42 |
Correct |
33 ms |
1772 KB |
Output is correct |
43 |
Correct |
4 ms |
492 KB |
Output is correct |
44 |
Correct |
21 ms |
1260 KB |
Output is correct |
45 |
Correct |
28 ms |
1516 KB |
Output is correct |
46 |
Correct |
35 ms |
1772 KB |
Output is correct |
47 |
Correct |
11 ms |
876 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
66 ms |
1772 KB |
Output is correct |
50 |
Correct |
40 ms |
1804 KB |
Output is correct |
51 |
Correct |
47 ms |
1644 KB |
Output is correct |
52 |
Correct |
47 ms |
1772 KB |
Output is correct |
53 |
Correct |
38 ms |
1900 KB |
Output is correct |
54 |
Correct |
71 ms |
1772 KB |
Output is correct |
55 |
Correct |
33 ms |
1644 KB |
Output is correct |
56 |
Correct |
43 ms |
1644 KB |
Output is correct |
57 |
Correct |
36 ms |
1644 KB |
Output is correct |
58 |
Correct |
235 ms |
1900 KB |
Output is correct |
59 |
Correct |
251 ms |
2156 KB |
Output is correct |
60 |
Correct |
232 ms |
1772 KB |
Output is correct |
61 |
Correct |
260 ms |
1900 KB |
Output is correct |
62 |
Correct |
229 ms |
1772 KB |
Output is correct |
63 |
Correct |
256 ms |
1900 KB |
Output is correct |
64 |
Correct |
224 ms |
1772 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |