//я так много думал, что опять попал
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define f first
#define s second
#define left(v) v + v
#define right(v) v + v + 1
#define ub upper_bound
#define lb lower_bound
using namespace std;
typedef long long ll;
//17 SEVENTEEN
const long double Pi = acos(-1.0);
const ll dx[] = {0,0,1,-1};
const ll dy[] = {1,-1,0,0};
const ll N = (ll) 1e6 + 17;
const ll M = (ll) 5e3 + 69;
const ll inf = (ll) 1e18 + 3;
const ll mod = (ll) 1e9 + 7;
ll sq(ll x) { return x * x; }
ll zxc = 1;
vector<ll> d;
map<pair<ll, ll>, ll> cnt;
void solve() {
ll n, k;
cin >> n >> k;
for(ll i = 2; i * i <= n; i++) {
if(!(n % i)) {
d.pb(i);
if(n / i != i) d.pb(n / i);
}
}
d.pb(1);
sort(all(d));
// for(ll x : d) cout << x << "\n";
while(k--) {
ll x, y;
cin >> x >> y >> x >> y;
for(ll val : d)
cnt[{val, ((x - 1) / val + (y - 1) / val + 2) % 2}]++;
}
ll ans = inf;
for(ll val : d) {
ll m = n / val, x;
if(m % 2) x = sq((m + 1) / 2) + sq(m / 2);
else x = sq(m) / 2;
ans = min(min(x * sq(val) - cnt[{val, 0}] + cnt[{val, 1}], (sq(m) - x) * sq(val) - cnt[{val, 1}] + cnt[{val, 0}]), ans);
}
cout << ans;
}
int main(/*Уверенно*/) {
ios_base::sync_with_stdio(0);
cin.tie(0);
/*
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
*/
// cin >> zxc;
while(zxc--) {
solve();
}
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 |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 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 |
19 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
204 KB |
Output is correct |
3 |
Correct |
12 ms |
312 KB |
Output is correct |
4 |
Correct |
13 ms |
332 KB |
Output is correct |
5 |
Correct |
18 ms |
316 KB |
Output is correct |
6 |
Correct |
11 ms |
312 KB |
Output is correct |
7 |
Correct |
2 ms |
320 KB |
Output is correct |
8 |
Correct |
10 ms |
312 KB |
Output is correct |
9 |
Correct |
26 ms |
204 KB |
Output is correct |
10 |
Correct |
14 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
216 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 |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
0 ms |
304 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 |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
216 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 |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
0 ms |
304 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 |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
8 ms |
520 KB |
Output is correct |
17 |
Correct |
23 ms |
724 KB |
Output is correct |
18 |
Correct |
35 ms |
708 KB |
Output is correct |
19 |
Correct |
68 ms |
708 KB |
Output is correct |
20 |
Correct |
77 ms |
680 KB |
Output is correct |
21 |
Correct |
23 ms |
704 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
16 ms |
460 KB |
Output is correct |
24 |
Correct |
28 ms |
644 KB |
Output is correct |
25 |
Correct |
6 ms |
324 KB |
Output is correct |
26 |
Correct |
19 ms |
596 KB |
Output is correct |
27 |
Correct |
22 ms |
688 KB |
Output is correct |
28 |
Correct |
28 ms |
700 KB |
Output is correct |
29 |
Correct |
10 ms |
460 KB |
Output is correct |
30 |
Correct |
2 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
204 KB |
Output is correct |
3 |
Correct |
12 ms |
312 KB |
Output is correct |
4 |
Correct |
13 ms |
332 KB |
Output is correct |
5 |
Correct |
18 ms |
316 KB |
Output is correct |
6 |
Correct |
11 ms |
312 KB |
Output is correct |
7 |
Correct |
2 ms |
320 KB |
Output is correct |
8 |
Correct |
10 ms |
312 KB |
Output is correct |
9 |
Correct |
26 ms |
204 KB |
Output is correct |
10 |
Correct |
14 ms |
308 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
216 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 |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
0 ms |
304 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 |
320 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
8 ms |
520 KB |
Output is correct |
27 |
Correct |
23 ms |
724 KB |
Output is correct |
28 |
Correct |
35 ms |
708 KB |
Output is correct |
29 |
Correct |
68 ms |
708 KB |
Output is correct |
30 |
Correct |
77 ms |
680 KB |
Output is correct |
31 |
Correct |
23 ms |
704 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
16 ms |
460 KB |
Output is correct |
34 |
Correct |
28 ms |
644 KB |
Output is correct |
35 |
Correct |
6 ms |
324 KB |
Output is correct |
36 |
Correct |
19 ms |
596 KB |
Output is correct |
37 |
Correct |
22 ms |
688 KB |
Output is correct |
38 |
Correct |
28 ms |
700 KB |
Output is correct |
39 |
Correct |
10 ms |
460 KB |
Output is correct |
40 |
Correct |
2 ms |
324 KB |
Output is correct |
41 |
Correct |
66 ms |
848 KB |
Output is correct |
42 |
Correct |
32 ms |
768 KB |
Output is correct |
43 |
Correct |
48 ms |
664 KB |
Output is correct |
44 |
Correct |
34 ms |
836 KB |
Output is correct |
45 |
Correct |
36 ms |
836 KB |
Output is correct |
46 |
Correct |
69 ms |
736 KB |
Output is correct |
47 |
Correct |
27 ms |
764 KB |
Output is correct |
48 |
Correct |
40 ms |
744 KB |
Output is correct |
49 |
Correct |
31 ms |
684 KB |
Output is correct |
50 |
Correct |
347 ms |
704 KB |
Output is correct |
51 |
Correct |
364 ms |
524 KB |
Output is correct |
52 |
Correct |
344 ms |
452 KB |
Output is correct |
53 |
Correct |
348 ms |
464 KB |
Output is correct |
54 |
Correct |
334 ms |
584 KB |
Output is correct |
55 |
Correct |
363 ms |
464 KB |
Output is correct |
56 |
Correct |
313 ms |
444 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 |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 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 |
19 ms |
204 KB |
Output is correct |
10 |
Correct |
5 ms |
204 KB |
Output is correct |
11 |
Correct |
12 ms |
312 KB |
Output is correct |
12 |
Correct |
13 ms |
332 KB |
Output is correct |
13 |
Correct |
18 ms |
316 KB |
Output is correct |
14 |
Correct |
11 ms |
312 KB |
Output is correct |
15 |
Correct |
2 ms |
320 KB |
Output is correct |
16 |
Correct |
10 ms |
312 KB |
Output is correct |
17 |
Correct |
26 ms |
204 KB |
Output is correct |
18 |
Correct |
14 ms |
308 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
216 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 |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
316 KB |
Output is correct |
27 |
Correct |
1 ms |
320 KB |
Output is correct |
28 |
Correct |
0 ms |
304 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 |
320 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
8 ms |
520 KB |
Output is correct |
35 |
Correct |
23 ms |
724 KB |
Output is correct |
36 |
Correct |
35 ms |
708 KB |
Output is correct |
37 |
Correct |
68 ms |
708 KB |
Output is correct |
38 |
Correct |
77 ms |
680 KB |
Output is correct |
39 |
Correct |
23 ms |
704 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
16 ms |
460 KB |
Output is correct |
42 |
Correct |
28 ms |
644 KB |
Output is correct |
43 |
Correct |
6 ms |
324 KB |
Output is correct |
44 |
Correct |
19 ms |
596 KB |
Output is correct |
45 |
Correct |
22 ms |
688 KB |
Output is correct |
46 |
Correct |
28 ms |
700 KB |
Output is correct |
47 |
Correct |
10 ms |
460 KB |
Output is correct |
48 |
Correct |
2 ms |
324 KB |
Output is correct |
49 |
Correct |
66 ms |
848 KB |
Output is correct |
50 |
Correct |
32 ms |
768 KB |
Output is correct |
51 |
Correct |
48 ms |
664 KB |
Output is correct |
52 |
Correct |
34 ms |
836 KB |
Output is correct |
53 |
Correct |
36 ms |
836 KB |
Output is correct |
54 |
Correct |
69 ms |
736 KB |
Output is correct |
55 |
Correct |
27 ms |
764 KB |
Output is correct |
56 |
Correct |
40 ms |
744 KB |
Output is correct |
57 |
Correct |
31 ms |
684 KB |
Output is correct |
58 |
Correct |
347 ms |
704 KB |
Output is correct |
59 |
Correct |
364 ms |
524 KB |
Output is correct |
60 |
Correct |
344 ms |
452 KB |
Output is correct |
61 |
Correct |
348 ms |
464 KB |
Output is correct |
62 |
Correct |
334 ms |
584 KB |
Output is correct |
63 |
Correct |
363 ms |
464 KB |
Output is correct |
64 |
Correct |
313 ms |
444 KB |
Output is correct |
65 |
Correct |
0 ms |
204 KB |
Output is correct |
66 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |