#include <bits/stdc++.h>
using namespace std;
#define N 200002
#define ff first
#define ss second
#define ll long long
vector<ll> di = {1};
ll dif[200005], res = 1 << 50;
inline ll get(ll x, ll d){
return x / (2 * d) * d + min(d, x % (2 * d));
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n, k, x1, x2, y1, y2, ex, ey, ox, oy;
cin>>n>>k;
for(int i = 2; i * i <= n; i++)
if(n % i == 0){
di.push_back(i);
if(i * i != n)
di.push_back(n / i);
}
for(int i = 0; i < di.size(); i++)
dif[i] = n * n - n * n / (di[i] * di[i]) / 2 * (di[i] * di[i]);
while(k--){
cin>>x1>>y1>>x2>>y2;
for(int i = 0; i < di.size(); i++){
ex = get(x2, di[i]) - get(x1 - 1, di[i]);
ox = x2 - x1 + 1 - ex;
ey = get(y2, di[i]) - get(y1 - 1, di[i]);
oy = y2 - y1 + 1 - ey;
dif[i] -= ex * ey + ox * oy;
dif[i] += ex * oy + ey * ox;
}
}
for(int i = 0; i < di.size(); i++)
res = min(res, min(dif[i], n * n - dif[i]));
cout<<res;
}
Compilation message
chessboard.cpp:10:28: warning: left shift count >= width of type [-Wshift-count-overflow]
ll dif[200005], res = 1 << 50;
^~
chessboard.cpp: In function 'int main()':
chessboard.cpp:33:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < di.size(); i++)
~~^~~~~~~~~~~
chessboard.cpp:38:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < di.size(); i++){
~~^~~~~~~~~~~
chessboard.cpp:48:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < di.size(); i++)
~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |