#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]-1)/m)%2==0 && ( (b[x]-1)/m)%2==0 ){
kolp1--;
}
else
if( ((a[x]-1)/m)%2!=0 && ((b[x]-1)/m)%2!=0 ){
kolp1--;
}
else {
kolp1++;
}
if( ((a[x]-1)/m)%2==0 && ((b[x]-1)/m)%2!=0 ){
kolp2--;
}
else
if( ((a[x]-1)/m)%2!=0 && ((b[x]-1)/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]-1)/m)%2==0 && ( (b[x]-1)/m)%2==0 ){
kolp1--;
}
else
if( ((a[x]-1)/m)%2!=0 && ((b[x]-1)/m)%2!=0 ){
kolp1--;
}
else {
kolp1++;
}
if( ((a[x]-1)/m)%2==0 && ((b[x]-1)/m)%2!=0 ){
kolp2--;
}
else
if( ((a[x]-1)/m)%2!=0 && ((b[x]-1)/m)%2==0 ){
kolp2--;
}
else {
kolp2++;
}
}
}
ans=min(ans,min(kolp1,kolp2));
}
}
cout<<ans;
}
/**
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
**/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
448 KB |
Output is correct |
5 |
Correct |
2 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
2 ms |
484 KB |
Output is correct |
8 |
Correct |
2 ms |
484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
1508 KB |
Output is correct |
2 |
Correct |
10 ms |
1508 KB |
Output is correct |
3 |
Correct |
21 ms |
2104 KB |
Output is correct |
4 |
Correct |
22 ms |
3020 KB |
Output is correct |
5 |
Correct |
29 ms |
4620 KB |
Output is correct |
6 |
Correct |
20 ms |
5080 KB |
Output is correct |
7 |
Correct |
6 ms |
5080 KB |
Output is correct |
8 |
Correct |
19 ms |
5980 KB |
Output is correct |
9 |
Correct |
48 ms |
6856 KB |
Output is correct |
10 |
Correct |
24 ms |
6856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6856 KB |
Output is correct |
2 |
Correct |
2 ms |
6856 KB |
Output is correct |
3 |
Correct |
2 ms |
6856 KB |
Output is correct |
4 |
Correct |
2 ms |
6856 KB |
Output is correct |
5 |
Correct |
2 ms |
6856 KB |
Output is correct |
6 |
Correct |
2 ms |
6856 KB |
Output is correct |
7 |
Correct |
2 ms |
6856 KB |
Output is correct |
8 |
Correct |
2 ms |
6856 KB |
Output is correct |
9 |
Correct |
2 ms |
6856 KB |
Output is correct |
10 |
Correct |
2 ms |
6856 KB |
Output is correct |
11 |
Correct |
2 ms |
6856 KB |
Output is correct |
12 |
Correct |
2 ms |
6856 KB |
Output is correct |
13 |
Correct |
3 ms |
6856 KB |
Output is correct |
14 |
Correct |
2 ms |
6856 KB |
Output is correct |
15 |
Correct |
3 ms |
6856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6856 KB |
Output is correct |
2 |
Correct |
2 ms |
6856 KB |
Output is correct |
3 |
Correct |
2 ms |
6856 KB |
Output is correct |
4 |
Correct |
2 ms |
6856 KB |
Output is correct |
5 |
Correct |
2 ms |
6856 KB |
Output is correct |
6 |
Correct |
2 ms |
6856 KB |
Output is correct |
7 |
Correct |
2 ms |
6856 KB |
Output is correct |
8 |
Correct |
2 ms |
6856 KB |
Output is correct |
9 |
Correct |
2 ms |
6856 KB |
Output is correct |
10 |
Correct |
2 ms |
6856 KB |
Output is correct |
11 |
Correct |
2 ms |
6856 KB |
Output is correct |
12 |
Correct |
2 ms |
6856 KB |
Output is correct |
13 |
Correct |
3 ms |
6856 KB |
Output is correct |
14 |
Correct |
2 ms |
6856 KB |
Output is correct |
15 |
Correct |
3 ms |
6856 KB |
Output is correct |
16 |
Correct |
15 ms |
6856 KB |
Output is correct |
17 |
Correct |
33 ms |
6856 KB |
Output is correct |
18 |
Correct |
51 ms |
7000 KB |
Output is correct |
19 |
Correct |
127 ms |
7000 KB |
Output is correct |
20 |
Correct |
148 ms |
7128 KB |
Output is correct |
21 |
Correct |
35 ms |
7128 KB |
Output is correct |
22 |
Correct |
3 ms |
7128 KB |
Output is correct |
23 |
Correct |
29 ms |
7128 KB |
Output is correct |
24 |
Correct |
44 ms |
7128 KB |
Output is correct |
25 |
Correct |
7 ms |
7128 KB |
Output is correct |
26 |
Correct |
29 ms |
7128 KB |
Output is correct |
27 |
Correct |
39 ms |
7128 KB |
Output is correct |
28 |
Correct |
48 ms |
7128 KB |
Output is correct |
29 |
Correct |
16 ms |
7128 KB |
Output is correct |
30 |
Correct |
4 ms |
7128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
1508 KB |
Output is correct |
2 |
Correct |
10 ms |
1508 KB |
Output is correct |
3 |
Correct |
21 ms |
2104 KB |
Output is correct |
4 |
Correct |
22 ms |
3020 KB |
Output is correct |
5 |
Correct |
29 ms |
4620 KB |
Output is correct |
6 |
Correct |
20 ms |
5080 KB |
Output is correct |
7 |
Correct |
6 ms |
5080 KB |
Output is correct |
8 |
Correct |
19 ms |
5980 KB |
Output is correct |
9 |
Correct |
48 ms |
6856 KB |
Output is correct |
10 |
Correct |
24 ms |
6856 KB |
Output is correct |
11 |
Correct |
2 ms |
6856 KB |
Output is correct |
12 |
Correct |
2 ms |
6856 KB |
Output is correct |
13 |
Correct |
2 ms |
6856 KB |
Output is correct |
14 |
Correct |
2 ms |
6856 KB |
Output is correct |
15 |
Correct |
2 ms |
6856 KB |
Output is correct |
16 |
Correct |
2 ms |
6856 KB |
Output is correct |
17 |
Correct |
2 ms |
6856 KB |
Output is correct |
18 |
Correct |
2 ms |
6856 KB |
Output is correct |
19 |
Correct |
2 ms |
6856 KB |
Output is correct |
20 |
Correct |
2 ms |
6856 KB |
Output is correct |
21 |
Correct |
2 ms |
6856 KB |
Output is correct |
22 |
Correct |
2 ms |
6856 KB |
Output is correct |
23 |
Correct |
3 ms |
6856 KB |
Output is correct |
24 |
Correct |
2 ms |
6856 KB |
Output is correct |
25 |
Correct |
3 ms |
6856 KB |
Output is correct |
26 |
Correct |
15 ms |
6856 KB |
Output is correct |
27 |
Correct |
33 ms |
6856 KB |
Output is correct |
28 |
Correct |
51 ms |
7000 KB |
Output is correct |
29 |
Correct |
127 ms |
7000 KB |
Output is correct |
30 |
Correct |
148 ms |
7128 KB |
Output is correct |
31 |
Correct |
35 ms |
7128 KB |
Output is correct |
32 |
Correct |
3 ms |
7128 KB |
Output is correct |
33 |
Correct |
29 ms |
7128 KB |
Output is correct |
34 |
Correct |
44 ms |
7128 KB |
Output is correct |
35 |
Correct |
7 ms |
7128 KB |
Output is correct |
36 |
Correct |
29 ms |
7128 KB |
Output is correct |
37 |
Correct |
39 ms |
7128 KB |
Output is correct |
38 |
Correct |
48 ms |
7128 KB |
Output is correct |
39 |
Correct |
16 ms |
7128 KB |
Output is correct |
40 |
Correct |
4 ms |
7128 KB |
Output is correct |
41 |
Correct |
118 ms |
7128 KB |
Output is correct |
42 |
Correct |
54 ms |
7128 KB |
Output is correct |
43 |
Correct |
73 ms |
7128 KB |
Output is correct |
44 |
Correct |
51 ms |
7128 KB |
Output is correct |
45 |
Correct |
47 ms |
8408 KB |
Output is correct |
46 |
Correct |
128 ms |
10596 KB |
Output is correct |
47 |
Correct |
41 ms |
11308 KB |
Output is correct |
48 |
Correct |
62 ms |
11308 KB |
Output is correct |
49 |
Correct |
47 ms |
11308 KB |
Output is correct |
50 |
Correct |
495 ms |
11528 KB |
Output is correct |
51 |
Correct |
511 ms |
11712 KB |
Output is correct |
52 |
Correct |
480 ms |
11712 KB |
Output is correct |
53 |
Correct |
530 ms |
11712 KB |
Output is correct |
54 |
Correct |
478 ms |
11712 KB |
Output is correct |
55 |
Correct |
557 ms |
11712 KB |
Output is correct |
56 |
Correct |
466 ms |
11712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
448 KB |
Output is correct |
5 |
Correct |
2 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
2 ms |
484 KB |
Output is correct |
8 |
Correct |
2 ms |
484 KB |
Output is correct |
9 |
Correct |
31 ms |
1508 KB |
Output is correct |
10 |
Correct |
10 ms |
1508 KB |
Output is correct |
11 |
Correct |
21 ms |
2104 KB |
Output is correct |
12 |
Correct |
22 ms |
3020 KB |
Output is correct |
13 |
Correct |
29 ms |
4620 KB |
Output is correct |
14 |
Correct |
20 ms |
5080 KB |
Output is correct |
15 |
Correct |
6 ms |
5080 KB |
Output is correct |
16 |
Correct |
19 ms |
5980 KB |
Output is correct |
17 |
Correct |
48 ms |
6856 KB |
Output is correct |
18 |
Correct |
24 ms |
6856 KB |
Output is correct |
19 |
Correct |
2 ms |
6856 KB |
Output is correct |
20 |
Correct |
2 ms |
6856 KB |
Output is correct |
21 |
Correct |
2 ms |
6856 KB |
Output is correct |
22 |
Correct |
2 ms |
6856 KB |
Output is correct |
23 |
Correct |
2 ms |
6856 KB |
Output is correct |
24 |
Correct |
2 ms |
6856 KB |
Output is correct |
25 |
Correct |
2 ms |
6856 KB |
Output is correct |
26 |
Correct |
2 ms |
6856 KB |
Output is correct |
27 |
Correct |
2 ms |
6856 KB |
Output is correct |
28 |
Correct |
2 ms |
6856 KB |
Output is correct |
29 |
Correct |
2 ms |
6856 KB |
Output is correct |
30 |
Correct |
2 ms |
6856 KB |
Output is correct |
31 |
Correct |
3 ms |
6856 KB |
Output is correct |
32 |
Correct |
2 ms |
6856 KB |
Output is correct |
33 |
Correct |
3 ms |
6856 KB |
Output is correct |
34 |
Correct |
15 ms |
6856 KB |
Output is correct |
35 |
Correct |
33 ms |
6856 KB |
Output is correct |
36 |
Correct |
51 ms |
7000 KB |
Output is correct |
37 |
Correct |
127 ms |
7000 KB |
Output is correct |
38 |
Correct |
148 ms |
7128 KB |
Output is correct |
39 |
Correct |
35 ms |
7128 KB |
Output is correct |
40 |
Correct |
3 ms |
7128 KB |
Output is correct |
41 |
Correct |
29 ms |
7128 KB |
Output is correct |
42 |
Correct |
44 ms |
7128 KB |
Output is correct |
43 |
Correct |
7 ms |
7128 KB |
Output is correct |
44 |
Correct |
29 ms |
7128 KB |
Output is correct |
45 |
Correct |
39 ms |
7128 KB |
Output is correct |
46 |
Correct |
48 ms |
7128 KB |
Output is correct |
47 |
Correct |
16 ms |
7128 KB |
Output is correct |
48 |
Correct |
4 ms |
7128 KB |
Output is correct |
49 |
Correct |
118 ms |
7128 KB |
Output is correct |
50 |
Correct |
54 ms |
7128 KB |
Output is correct |
51 |
Correct |
73 ms |
7128 KB |
Output is correct |
52 |
Correct |
51 ms |
7128 KB |
Output is correct |
53 |
Correct |
47 ms |
8408 KB |
Output is correct |
54 |
Correct |
128 ms |
10596 KB |
Output is correct |
55 |
Correct |
41 ms |
11308 KB |
Output is correct |
56 |
Correct |
62 ms |
11308 KB |
Output is correct |
57 |
Correct |
47 ms |
11308 KB |
Output is correct |
58 |
Correct |
495 ms |
11528 KB |
Output is correct |
59 |
Correct |
511 ms |
11712 KB |
Output is correct |
60 |
Correct |
480 ms |
11712 KB |
Output is correct |
61 |
Correct |
530 ms |
11712 KB |
Output is correct |
62 |
Correct |
478 ms |
11712 KB |
Output is correct |
63 |
Correct |
557 ms |
11712 KB |
Output is correct |
64 |
Correct |
466 ms |
11712 KB |
Output is correct |
65 |
Correct |
2 ms |
11712 KB |
Output is correct |
66 |
Incorrect |
2 ms |
11712 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |