#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll> di = {1};
ll dif[200005], res = 1e12;
inline find(ll x, ll d){
return x / (2 * d) * d + min(x % (2 * d), d);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, k, ox, ex, oy, ey;
cin>>n>>k;
for(ll i = 2; i * i <= n; i++){
if(n % i == 0){
di.push_back(i);
if(i * i != n) di.push_back(n / i);
}
}
for(ll i = 0; i < di.size(); i++)
dif[i] = n * n - n * n / (di[i] * di[i]) / 2 * (di[i] * di[i]);
while(k--){
ll x1, x2, y1, y2;
cin>>x1>>y1>>x2>>y2;
x1--; y1--;
for(ll i = 0; i < di.size(); i++){
ex = find(x2, di[i]) - find(x1, di[i]);
ox = x2 - x1 - ex;
ey = find(y2, di[i]) - find(y1, di[i]);
oy = y2 - y1 - ey;
dif[i] += ex * oy + ey * ox - ex * ey - ox * oy;
}
}
for(ll i = 0; i < di.size(); i++)
res = min(res, min(dif[i], n * n - dif[i]));
cout<<res;
}
Compilation message
chessboard.cpp:8:23: error: ISO C++ forbids declaration of 'find' with no type [-fpermissive]
inline find(ll x, ll d){
^
chessboard.cpp: In function 'int main()':
chessboard.cpp:26:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll i = 0; i < di.size(); i++)
~~^~~~~~~~~~~
chessboard.cpp:33:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll i = 0; i < di.size(); i++){
~~^~~~~~~~~~~
chessboard.cpp:42:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll i = 0; i < di.size(); i++)
~~^~~~~~~~~~~