#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define ld long double
#define all(_v) _v.begin(), _v.end()
#define sz(_v) (int)_v.size()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define veci vector <int>
#define vecll vector <ll>
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;
const int MAXN = 2e5 + 10;
ll n;
ll cnt[MAXN];
ll get(ll r, ll k) {
ll nr = (r % k == 0 ? r : r - r % k);
ll bl = nr / k;
ll cnt = (bl + 1) / 2 * k;
if(bl % 2 == 0) cnt += r - nr;
return cnt;
}
void solve() {
int k;
cin >> n >> k;
veci dv;
dv.pb(1);
for(ll i = 2; i * i <= n; ++i) {
if(n % i == 0) {
dv.pb(i);
if(i * i != n) dv.pb(n / i);
}
}
sort(all(dv));
for(auto i : dv) {
ll cnt1 = get(n, i);
cnt[i] = cnt1 * i * (((n / i) + 1) / 2) + (n - cnt1) * i * (n / i - (((n / i) + 1) / 2));
}
for(int rect = 1; rect <= k; ++rect) {
ll x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
for(auto i : dv) {
ll row_cnt[2];
row_cnt[1] = get(x2, i) - get(x1 - 1, i);
row_cnt[0] = x2 - x1 + 1 - row_cnt[1];
ll col_cnt[2];
col_cnt[1] = get(y2, i) - get(y2 - 1, i);
col_cnt[0] = y2 - y1 + 1 - col_cnt[1];
cnt[i] -= row_cnt[1] * col_cnt[1];
cnt[i] -= row_cnt[0] * col_cnt[0];
cnt[i] += row_cnt[0] * col_cnt[1];
cnt[i] += row_cnt[1] * col_cnt[0];
}
}
ll ans = 1e18;
for(auto i : dv) ans = min(ans, min(cnt[i], n * n - cnt[i]));
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int CNT_TESTS = 1;
///cin >> CNT_TESTS;
for(int NUMCASE = 1; NUMCASE <= CNT_TESTS; ++NUMCASE) {
solve();
if(NUMCASE != CNT_TESTS) cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
300 KB |
Output is correct |
2 |
Correct |
6 ms |
204 KB |
Output is correct |
3 |
Correct |
14 ms |
204 KB |
Output is correct |
4 |
Correct |
16 ms |
204 KB |
Output is correct |
5 |
Correct |
19 ms |
204 KB |
Output is correct |
6 |
Correct |
12 ms |
328 KB |
Output is correct |
7 |
Correct |
3 ms |
216 KB |
Output is correct |
8 |
Correct |
12 ms |
320 KB |
Output is correct |
9 |
Correct |
31 ms |
208 KB |
Output is correct |
10 |
Correct |
25 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 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 |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 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 |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
12 ms |
320 KB |
Output is correct |
17 |
Correct |
26 ms |
300 KB |
Output is correct |
18 |
Correct |
44 ms |
304 KB |
Output is correct |
19 |
Correct |
124 ms |
204 KB |
Output is correct |
20 |
Correct |
140 ms |
204 KB |
Output is correct |
21 |
Correct |
23 ms |
320 KB |
Output is correct |
22 |
Correct |
1 ms |
216 KB |
Output is correct |
23 |
Correct |
24 ms |
332 KB |
Output is correct |
24 |
Correct |
37 ms |
216 KB |
Output is correct |
25 |
Correct |
5 ms |
216 KB |
Output is correct |
26 |
Correct |
20 ms |
216 KB |
Output is correct |
27 |
Correct |
31 ms |
320 KB |
Output is correct |
28 |
Correct |
34 ms |
312 KB |
Output is correct |
29 |
Correct |
9 ms |
216 KB |
Output is correct |
30 |
Correct |
2 ms |
216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
300 KB |
Output is correct |
2 |
Correct |
6 ms |
204 KB |
Output is correct |
3 |
Correct |
14 ms |
204 KB |
Output is correct |
4 |
Correct |
16 ms |
204 KB |
Output is correct |
5 |
Correct |
19 ms |
204 KB |
Output is correct |
6 |
Correct |
12 ms |
328 KB |
Output is correct |
7 |
Correct |
3 ms |
216 KB |
Output is correct |
8 |
Correct |
12 ms |
320 KB |
Output is correct |
9 |
Correct |
31 ms |
208 KB |
Output is correct |
10 |
Correct |
25 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 |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 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 |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
12 ms |
320 KB |
Output is correct |
27 |
Correct |
26 ms |
300 KB |
Output is correct |
28 |
Correct |
44 ms |
304 KB |
Output is correct |
29 |
Correct |
124 ms |
204 KB |
Output is correct |
30 |
Correct |
140 ms |
204 KB |
Output is correct |
31 |
Correct |
23 ms |
320 KB |
Output is correct |
32 |
Correct |
1 ms |
216 KB |
Output is correct |
33 |
Correct |
24 ms |
332 KB |
Output is correct |
34 |
Correct |
37 ms |
216 KB |
Output is correct |
35 |
Correct |
5 ms |
216 KB |
Output is correct |
36 |
Correct |
20 ms |
216 KB |
Output is correct |
37 |
Correct |
31 ms |
320 KB |
Output is correct |
38 |
Correct |
34 ms |
312 KB |
Output is correct |
39 |
Correct |
9 ms |
216 KB |
Output is correct |
40 |
Correct |
2 ms |
216 KB |
Output is correct |
41 |
Correct |
115 ms |
352 KB |
Output is correct |
42 |
Correct |
44 ms |
216 KB |
Output is correct |
43 |
Correct |
65 ms |
344 KB |
Output is correct |
44 |
Correct |
38 ms |
216 KB |
Output is correct |
45 |
Correct |
36 ms |
308 KB |
Output is correct |
46 |
Correct |
127 ms |
344 KB |
Output is correct |
47 |
Correct |
28 ms |
216 KB |
Output is correct |
48 |
Correct |
52 ms |
324 KB |
Output is correct |
49 |
Correct |
39 ms |
216 KB |
Output is correct |
50 |
Correct |
561 ms |
400 KB |
Output is correct |
51 |
Correct |
592 ms |
332 KB |
Output is correct |
52 |
Correct |
557 ms |
388 KB |
Output is correct |
53 |
Correct |
592 ms |
332 KB |
Output is correct |
54 |
Correct |
559 ms |
392 KB |
Output is correct |
55 |
Correct |
627 ms |
388 KB |
Output is correct |
56 |
Correct |
543 ms |
392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
22 ms |
300 KB |
Output is correct |
10 |
Correct |
6 ms |
204 KB |
Output is correct |
11 |
Correct |
14 ms |
204 KB |
Output is correct |
12 |
Correct |
16 ms |
204 KB |
Output is correct |
13 |
Correct |
19 ms |
204 KB |
Output is correct |
14 |
Correct |
12 ms |
328 KB |
Output is correct |
15 |
Correct |
3 ms |
216 KB |
Output is correct |
16 |
Correct |
12 ms |
320 KB |
Output is correct |
17 |
Correct |
31 ms |
208 KB |
Output is correct |
18 |
Correct |
25 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 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 |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
12 ms |
320 KB |
Output is correct |
35 |
Correct |
26 ms |
300 KB |
Output is correct |
36 |
Correct |
44 ms |
304 KB |
Output is correct |
37 |
Correct |
124 ms |
204 KB |
Output is correct |
38 |
Correct |
140 ms |
204 KB |
Output is correct |
39 |
Correct |
23 ms |
320 KB |
Output is correct |
40 |
Correct |
1 ms |
216 KB |
Output is correct |
41 |
Correct |
24 ms |
332 KB |
Output is correct |
42 |
Correct |
37 ms |
216 KB |
Output is correct |
43 |
Correct |
5 ms |
216 KB |
Output is correct |
44 |
Correct |
20 ms |
216 KB |
Output is correct |
45 |
Correct |
31 ms |
320 KB |
Output is correct |
46 |
Correct |
34 ms |
312 KB |
Output is correct |
47 |
Correct |
9 ms |
216 KB |
Output is correct |
48 |
Correct |
2 ms |
216 KB |
Output is correct |
49 |
Correct |
115 ms |
352 KB |
Output is correct |
50 |
Correct |
44 ms |
216 KB |
Output is correct |
51 |
Correct |
65 ms |
344 KB |
Output is correct |
52 |
Correct |
38 ms |
216 KB |
Output is correct |
53 |
Correct |
36 ms |
308 KB |
Output is correct |
54 |
Correct |
127 ms |
344 KB |
Output is correct |
55 |
Correct |
28 ms |
216 KB |
Output is correct |
56 |
Correct |
52 ms |
324 KB |
Output is correct |
57 |
Correct |
39 ms |
216 KB |
Output is correct |
58 |
Correct |
561 ms |
400 KB |
Output is correct |
59 |
Correct |
592 ms |
332 KB |
Output is correct |
60 |
Correct |
557 ms |
388 KB |
Output is correct |
61 |
Correct |
592 ms |
332 KB |
Output is correct |
62 |
Correct |
559 ms |
392 KB |
Output is correct |
63 |
Correct |
627 ms |
388 KB |
Output is correct |
64 |
Correct |
543 ms |
392 KB |
Output is correct |
65 |
Correct |
1 ms |
216 KB |
Output is correct |
66 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |