#include<bits/stdc++.h>
#define ll long long
using namespace std;
///map< ll , ll > dp[101101];
ll a[101101], b[101101];
int main(){
ios_base::sync_with_stdio(0);
ll n, k;
cin>>n>>k;
for( ll i =1; i <= k ; i ++ ){
cin>>a[i]>>b[i]>>a[i]>>b[i];
}
ll ans = 10000000000;
for( ll i = 1 ; i*i <= n ; i ++ ){
if( n % i == 0 ){
ll m=i, kolp1=0,kolp2=0 ;
kolp1=((n*n)/(m*m))/2+(((n*n)/(m*m))%2);
kolp2=((n*n)/(m*m))/2;
kolp1=kolp1*m*m;
kolp2=kolp2*m*m;
//cout<<kolp1<<' '<<kolp2<<' '<<m<<endl;
for( ll x = 1; x <= k ; x ++ ){
if( (a[x]/m)%2==0 && (b[x]/m)%2!=0 ){
kolp1--;
}
else
if( (a[x]/m)%2!=0 && (b[x]/m)%2==0 ){
kolp1--;
}
else {
kolp1++;
}
if( (a[x]/m)%2==0 && (b[x]/m)%2==0 ){
kolp2--;
}
else
if( (a[x]/m)%2!=0 && (b[x]/m)%2!=0 ){
kolp2--;
}
else {
kolp2++;
}
}
// cout<<kolp1<<' '<<kolp2<<' '<<m<<endl;
ans=min(ans,min(kolp1,kolp2));
m=n/i;
if( m != n ){
kolp1=((n*n)/(m*m))/2+((n*n)/(m*m))%2;
kolp2=((n*n)/(m*m))/2;
kolp1=kolp1*m*m;
kolp2=kolp2*m*m;
/// cout<<kolp1<<' '<<kolp2<<' '<<m<<endl;
for( ll x = 1; x <= k ; x ++ ){
if( (a[x]/m)%2==0 && (b[x]/m)%2!=0 ){
kolp1--;
}
else
if( (a[x]/m)%2!=0 && (b[x]/m)%2==0 ){
kolp1--;
}
else {
kolp1++;
}
if( (a[x]/m)%2==0 && (b[x]/m)%2==0 ){
kolp2--;
}
else
if( (a[x]/m)%2!=0 && (b[x]/m)%2!=0 ){
kolp2--;
}
else {
kolp2++;
}
}
}
ans=min(ans,min(kolp1,kolp2));
}
}
cout<<ans;
}
/**
3 3
2 2 2 2
2 3 2 3
3 2 3 2
//////
9 10
1 1 1 1
4 4 4 4
4 5 4 5
4 6 4 6
5 4 5 4
5 5 5 5
5 6 5 6
6 4 6 4
6 5 6 5
6 6 6 6
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
464 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
464 KB |
Output is correct |
5 |
Correct |
2 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
584 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
0 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
1368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
1368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
464 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
464 KB |
Output is correct |
5 |
Correct |
2 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
584 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
0 ms |
588 KB |
Output is correct |
9 |
Incorrect |
31 ms |
1368 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |