#include <bits/stdc++.h>
using namespace std;
#define lo long
const int lmax=1999999999;
const long long lmx=1999999999999999999;
int n,k;
long long ans=lmx,ansT;
int a[100003],b[100003],c[100003],d[100004];
int main(){std::ios::sync_with_stdio(false);
cin>>n>>k;
ansT=0LL;
for(long long i=0;i<k;i++)
{
cin>>a[i]>>b[i]>>c[i]>>d[i];
a[i]--,b[i]--,c[i]--,d[i]--;
}
ans=lmax;
for(int j = 1; j < n; ++j)
if(n % j == 0) {
ansT = 0;
for(int i = 0; i < k; ++i)
if((a[i]/j + b[i]/j) % 2 == 0)
++ansT;
ansT = ansT * 2 - k;
if(ansT + (long long)n * n / j / j / 2 * j * j < ans)
ans = ansT + (long long)n * n / j / j / 2 * j * j;
ansT = -ansT;
if(ansT + ((long long)n * n / j / j + 1) / 2 * j * j < ans)
ans = ansT + ((long long)n * n / j / j + 1) / 2 * j * j;
}
//cout<<ansT+K-ansS<<" "<<ansS+k-ansT<<endl;
cout<<ans<<endl;
}
/*
* *
* * * *
* * * *
* * * *
* * * *
* * *
* *
* *
* *
* *
* *
* *
* *
* *
*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
456 KB |
Output is correct |
3 |
Correct |
2 ms |
472 KB |
Output is correct |
4 |
Correct |
2 ms |
472 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
564 KB |
Output is correct |
8 |
Correct |
2 ms |
564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
1460 KB |
Output is correct |
2 |
Correct |
9 ms |
1460 KB |
Output is correct |
3 |
Incorrect |
20 ms |
1460 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1460 KB |
Output is correct |
2 |
Correct |
2 ms |
1460 KB |
Output is correct |
3 |
Correct |
2 ms |
1460 KB |
Output is correct |
4 |
Correct |
3 ms |
1460 KB |
Output is correct |
5 |
Correct |
3 ms |
1460 KB |
Output is correct |
6 |
Correct |
2 ms |
1460 KB |
Output is correct |
7 |
Correct |
2 ms |
1460 KB |
Output is correct |
8 |
Correct |
2 ms |
1460 KB |
Output is correct |
9 |
Correct |
3 ms |
1460 KB |
Output is correct |
10 |
Correct |
2 ms |
1460 KB |
Output is correct |
11 |
Correct |
2 ms |
1460 KB |
Output is correct |
12 |
Correct |
2 ms |
1460 KB |
Output is correct |
13 |
Correct |
2 ms |
1460 KB |
Output is correct |
14 |
Correct |
2 ms |
1460 KB |
Output is correct |
15 |
Correct |
3 ms |
1460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1460 KB |
Output is correct |
2 |
Correct |
2 ms |
1460 KB |
Output is correct |
3 |
Correct |
2 ms |
1460 KB |
Output is correct |
4 |
Correct |
3 ms |
1460 KB |
Output is correct |
5 |
Correct |
3 ms |
1460 KB |
Output is correct |
6 |
Correct |
2 ms |
1460 KB |
Output is correct |
7 |
Correct |
2 ms |
1460 KB |
Output is correct |
8 |
Correct |
2 ms |
1460 KB |
Output is correct |
9 |
Correct |
3 ms |
1460 KB |
Output is correct |
10 |
Correct |
2 ms |
1460 KB |
Output is correct |
11 |
Correct |
2 ms |
1460 KB |
Output is correct |
12 |
Correct |
2 ms |
1460 KB |
Output is correct |
13 |
Correct |
2 ms |
1460 KB |
Output is correct |
14 |
Correct |
2 ms |
1460 KB |
Output is correct |
15 |
Correct |
3 ms |
1460 KB |
Output is correct |
16 |
Correct |
15 ms |
1460 KB |
Output is correct |
17 |
Correct |
35 ms |
1876 KB |
Output is correct |
18 |
Correct |
39 ms |
2260 KB |
Output is correct |
19 |
Correct |
49 ms |
2260 KB |
Output is correct |
20 |
Correct |
56 ms |
2260 KB |
Output is correct |
21 |
Correct |
32 ms |
2260 KB |
Output is correct |
22 |
Correct |
3 ms |
2260 KB |
Output is correct |
23 |
Correct |
20 ms |
2260 KB |
Output is correct |
24 |
Correct |
62 ms |
2260 KB |
Output is correct |
25 |
Correct |
6 ms |
2260 KB |
Output is correct |
26 |
Correct |
26 ms |
2260 KB |
Output is correct |
27 |
Correct |
36 ms |
2260 KB |
Output is correct |
28 |
Correct |
41 ms |
2260 KB |
Output is correct |
29 |
Correct |
15 ms |
2260 KB |
Output is correct |
30 |
Correct |
5 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
1460 KB |
Output is correct |
2 |
Correct |
9 ms |
1460 KB |
Output is correct |
3 |
Incorrect |
20 ms |
1460 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
456 KB |
Output is correct |
3 |
Correct |
2 ms |
472 KB |
Output is correct |
4 |
Correct |
2 ms |
472 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
564 KB |
Output is correct |
8 |
Correct |
2 ms |
564 KB |
Output is correct |
9 |
Correct |
31 ms |
1460 KB |
Output is correct |
10 |
Correct |
9 ms |
1460 KB |
Output is correct |
11 |
Incorrect |
20 ms |
1460 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |