#include <bits/stdc++.h>
using namespace std;
#define lo long
const int lmax=1999999999;
const long long lmx=1999999999999999999;
long long n;
long long k;
long long ans=lmax,ansT,ansS;
long long a[100003],b[100003],c[100003],d[100004];
vector<long long>v;
long long k1;
int main(){std::ios::sync_with_stdio(false);
cin>>n>>k;
ansT=ansS=0LL;
for(long long i=1LL;i<n;i++)
{
if(n%i==0)
{
v.push_back(i);
}
}
ansT=ansS=0;
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=0;j<v.size();j++){
long long p=v[j];
ansS=ansT=0;
for(int i=0;i<k;i++)
{
{
long long q1=(a[i])/p;
long long q2=(b[i])/p;
long long q=q1+q2;
if((q)%2==0)
{
ansT++;
}
else
{
ansS++;
}
}
}
long long O=ansT-ansS;
//---------------
long long o=n/v[j];
//--------------
if(O+n*n/v[j]/v[j]/2LL*v[j]*v[j]<ans)
ans=O+n*n/v[j]/v[j]/2LL*v[j]*v[j];
O=ansS-ansT;
if(O+(n*n/v[j]/v[j]+1LL)/2LL*v[j]*v[j]<ans)
ans=O+(n*n/v[j]/v[j]+1LL)/2LL*v[j]*v[j];
}
//cout<<ansT+K-ansS<<" "<<ansS+k-ansT<<endl;
cout<<ans<<endl;
}
/*
* *
* * * *
* * * *
* * * *
* * * *
* * *
* *
* *
* *
* *
* *
* *
* *
* *
*
*/
Compilation message
chessboard.cpp: In function 'int main()':
chessboard.cpp:29:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<v.size();j++){
~^~~~~~~~~
chessboard.cpp:51:11: warning: unused variable 'o' [-Wunused-variable]
long long o=n/v[j];
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
540 KB |
Output is correct |
4 |
Correct |
2 ms |
540 KB |
Output is correct |
5 |
Correct |
3 ms |
540 KB |
Output is correct |
6 |
Correct |
2 ms |
540 KB |
Output is correct |
7 |
Correct |
2 ms |
540 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
2540 KB |
Output is correct |
2 |
Correct |
10 ms |
2540 KB |
Output is correct |
3 |
Incorrect |
27 ms |
2540 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2540 KB |
Output is correct |
2 |
Correct |
2 ms |
2540 KB |
Output is correct |
3 |
Correct |
2 ms |
2540 KB |
Output is correct |
4 |
Correct |
3 ms |
2540 KB |
Output is correct |
5 |
Correct |
3 ms |
2540 KB |
Output is correct |
6 |
Correct |
2 ms |
2540 KB |
Output is correct |
7 |
Correct |
3 ms |
2540 KB |
Output is correct |
8 |
Correct |
2 ms |
2540 KB |
Output is correct |
9 |
Correct |
2 ms |
2540 KB |
Output is correct |
10 |
Correct |
2 ms |
2540 KB |
Output is correct |
11 |
Correct |
2 ms |
2540 KB |
Output is correct |
12 |
Correct |
3 ms |
2540 KB |
Output is correct |
13 |
Correct |
3 ms |
2540 KB |
Output is correct |
14 |
Correct |
3 ms |
2540 KB |
Output is correct |
15 |
Correct |
3 ms |
2540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2540 KB |
Output is correct |
2 |
Correct |
2 ms |
2540 KB |
Output is correct |
3 |
Correct |
2 ms |
2540 KB |
Output is correct |
4 |
Correct |
3 ms |
2540 KB |
Output is correct |
5 |
Correct |
3 ms |
2540 KB |
Output is correct |
6 |
Correct |
2 ms |
2540 KB |
Output is correct |
7 |
Correct |
3 ms |
2540 KB |
Output is correct |
8 |
Correct |
2 ms |
2540 KB |
Output is correct |
9 |
Correct |
2 ms |
2540 KB |
Output is correct |
10 |
Correct |
2 ms |
2540 KB |
Output is correct |
11 |
Correct |
2 ms |
2540 KB |
Output is correct |
12 |
Correct |
3 ms |
2540 KB |
Output is correct |
13 |
Correct |
3 ms |
2540 KB |
Output is correct |
14 |
Correct |
3 ms |
2540 KB |
Output is correct |
15 |
Correct |
3 ms |
2540 KB |
Output is correct |
16 |
Correct |
22 ms |
2540 KB |
Output is correct |
17 |
Correct |
40 ms |
3196 KB |
Output is correct |
18 |
Correct |
51 ms |
3708 KB |
Output is correct |
19 |
Correct |
137 ms |
3708 KB |
Output is correct |
20 |
Correct |
138 ms |
3708 KB |
Output is correct |
21 |
Correct |
35 ms |
3708 KB |
Output is correct |
22 |
Correct |
2 ms |
3708 KB |
Output is correct |
23 |
Correct |
29 ms |
3708 KB |
Output is correct |
24 |
Correct |
56 ms |
3708 KB |
Output is correct |
25 |
Correct |
7 ms |
3708 KB |
Output is correct |
26 |
Correct |
30 ms |
3708 KB |
Output is correct |
27 |
Correct |
43 ms |
3708 KB |
Output is correct |
28 |
Correct |
49 ms |
3708 KB |
Output is correct |
29 |
Correct |
17 ms |
3708 KB |
Output is correct |
30 |
Correct |
5 ms |
3708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
2540 KB |
Output is correct |
2 |
Correct |
10 ms |
2540 KB |
Output is correct |
3 |
Incorrect |
27 ms |
2540 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 |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
540 KB |
Output is correct |
4 |
Correct |
2 ms |
540 KB |
Output is correct |
5 |
Correct |
3 ms |
540 KB |
Output is correct |
6 |
Correct |
2 ms |
540 KB |
Output is correct |
7 |
Correct |
2 ms |
540 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
37 ms |
2540 KB |
Output is correct |
10 |
Correct |
10 ms |
2540 KB |
Output is correct |
11 |
Incorrect |
27 ms |
2540 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |