//Euzibillahiminesseqtanirracim Bismillahirrahmanirrahim
/*
ID:
TASK:
LANG: C++
*/
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define PII pair<int,int>
#define inf 100000000001
using namespace std;
long long n, m, ans = inf , r;
double l;
pair<long long, long long> d[100001];
vector<long long>v;
void f(int x1,int q1,int x2,int q2){
for(auto x:v){
if( (x1%(2*x) < x && q1%(2*x) < x) || (x1%(2*x) >= x && q1%(2*x) >= x) ){
d[x].ff--;
d[x].ss++;
}
else{
d[x].ff++;
d[x].ss--;
}
}
}
long long x1, q1, x2, q2;
int main()
{
cin>>n>>m;
v.pb(1);
for(int i=2;i<=sqrt(n);i++) if(n%i == 0){
v.pb(i);
v.pb(n/i);
}
r = sqrt(n);
l = sqrt(n);
if(l == r) v.pop_back();
for(auto x:v){
d[x].ff = (( (n/x)*(n/x) )/ 2 + ( (n/x)*(n/x) )% 2 ) * x*x;
d[x].ss = n*n - d[x].ff;
}
while(m--){
cin>>x1>>q1>>x2>>q2;
f(x1 - 1 ,q1 - 1 ,x2 - 1 ,q2 - 1 );
}
for(auto x:v){
ans = min(ans , min( d[x].ff , d[x].ss ));
}
cout<<ans;
}
/*
_________oBBBBB8o oBBBBBBB8
_____o8BBBBBBBBBBB BBBBBBBBB8 o88o
___o8BBBBBB**8BBBB BBBBBBBBBB oBBBBBBBo
__oBBBBBBB* *** BBBBBBBBBB BBBBBBBBBBo
_8BBBBBBBBBBooooo *BBBBBBB8 *BB* 8BBBBBBo
_8BBBBBBBBBBBBBBBB8ooBBBBBBB8 8BBBBBBB8
__*BBBBBBBBBBBBBBBBBBBBBBBBBB8 o88BB88BBBBBBBBBBBB
____*BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB8
______**8BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB*
___________*BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB8*
____________*BBBBBBBBBBBBBBBBBBBBBBBB8888**
_____________BBBBBBBBBBBBBBBBBBBBBBB*
_____________*BBBBBBBBBBBBBBBBBBBBB*
______________*BBBBBBBBBBBBBBBBBB8
_______________*BBBBBBBBBBBBBBBB*
________________8BBBBBBBBBBBBBBB8
_________________8BBBBBBBBBBBBBBBo
__________________BBBBBBBBBBBBBBB8
__________________BBBBBBBBBBBBBBBB
__________________8BBBBBBBBBBBBBBB8
__________________*BBBBBBBBBBBBBBBB
__________________8BBBBBBBBBBBBBBBB8
_________________oBBBBBBBBBBBBBBBBBB
________________oBBBBBBBBBBBBBBBBBBB
________________BBBBBBBBBBBBBBBBBBBB
_______________8BBBBBBBBBBBBBBBBBBB8
______________oBBBBBBBBB88BBBBBBBBB8
______________8BBBBBBBBB*8BBBBBBBBB*
______________BBBBBBBBB* BBBBBBBBB8
______________BBBBBBBB8 oBBBBBBBBB*
______________8BBBBBBB oBBBBBBBB*
______________BBBBBBB* 8BBBBBBB*
_____________8BBBBBB* BBBBBBB*
____________8BBBBBB8 oBBBBBB8
___________8BBBBBB8 8BBBBBB*
__________oBBBBBB8 BBBBBBB8
__________BBBBBBB8 BBBBBBBB*
_________oBBBBBBB8 BBBBBBBB
_________8BBBBBB8 BBBBBBB*
_________BBBBBB* 8BBBBB*
________oBBBB8 BBBBB*
________oBBB8 BBBB*
________BBBB8 8BBBBo
_______8BBBB* oBBBBBBo
______8BBBB* *BBBBBBBB8o
______BBBBB* *88BBBo
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
476 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
476 KB |
Output is correct |
5 |
Correct |
2 ms |
496 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
552 KB |
Output is correct |
8 |
Correct |
2 ms |
552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
2008 KB |
Output is correct |
2 |
Correct |
24 ms |
2524 KB |
Output is correct |
3 |
Correct |
62 ms |
3328 KB |
Output is correct |
4 |
Correct |
54 ms |
4140 KB |
Output is correct |
5 |
Correct |
77 ms |
5416 KB |
Output is correct |
6 |
Correct |
50 ms |
5804 KB |
Output is correct |
7 |
Correct |
12 ms |
5804 KB |
Output is correct |
8 |
Correct |
50 ms |
5892 KB |
Output is correct |
9 |
Correct |
123 ms |
5892 KB |
Output is correct |
10 |
Correct |
71 ms |
6028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6028 KB |
Output is correct |
2 |
Correct |
2 ms |
6088 KB |
Output is correct |
3 |
Correct |
2 ms |
6104 KB |
Output is correct |
4 |
Correct |
4 ms |
6236 KB |
Output is correct |
5 |
Correct |
3 ms |
6236 KB |
Output is correct |
6 |
Correct |
3 ms |
6236 KB |
Output is correct |
7 |
Correct |
3 ms |
6236 KB |
Output is correct |
8 |
Correct |
3 ms |
6236 KB |
Output is correct |
9 |
Correct |
3 ms |
6236 KB |
Output is correct |
10 |
Correct |
2 ms |
6236 KB |
Output is correct |
11 |
Correct |
3 ms |
6236 KB |
Output is correct |
12 |
Correct |
3 ms |
6236 KB |
Output is correct |
13 |
Correct |
3 ms |
6236 KB |
Output is correct |
14 |
Correct |
3 ms |
6236 KB |
Output is correct |
15 |
Correct |
3 ms |
6236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6028 KB |
Output is correct |
2 |
Correct |
2 ms |
6088 KB |
Output is correct |
3 |
Correct |
2 ms |
6104 KB |
Output is correct |
4 |
Correct |
4 ms |
6236 KB |
Output is correct |
5 |
Correct |
3 ms |
6236 KB |
Output is correct |
6 |
Correct |
3 ms |
6236 KB |
Output is correct |
7 |
Correct |
3 ms |
6236 KB |
Output is correct |
8 |
Correct |
3 ms |
6236 KB |
Output is correct |
9 |
Correct |
3 ms |
6236 KB |
Output is correct |
10 |
Correct |
2 ms |
6236 KB |
Output is correct |
11 |
Correct |
3 ms |
6236 KB |
Output is correct |
12 |
Correct |
3 ms |
6236 KB |
Output is correct |
13 |
Correct |
3 ms |
6236 KB |
Output is correct |
14 |
Correct |
3 ms |
6236 KB |
Output is correct |
15 |
Correct |
3 ms |
6236 KB |
Output is correct |
16 |
Correct |
33 ms |
6628 KB |
Output is correct |
17 |
Correct |
91 ms |
6840 KB |
Output is correct |
18 |
Correct |
113 ms |
6852 KB |
Output is correct |
19 |
Correct |
183 ms |
6852 KB |
Output is correct |
20 |
Correct |
206 ms |
6852 KB |
Output is correct |
21 |
Correct |
85 ms |
6852 KB |
Output is correct |
22 |
Correct |
3 ms |
6852 KB |
Output is correct |
23 |
Correct |
57 ms |
6852 KB |
Output is correct |
24 |
Correct |
102 ms |
6852 KB |
Output is correct |
25 |
Correct |
13 ms |
6852 KB |
Output is correct |
26 |
Correct |
65 ms |
6852 KB |
Output is correct |
27 |
Correct |
83 ms |
6852 KB |
Output is correct |
28 |
Correct |
106 ms |
6852 KB |
Output is correct |
29 |
Correct |
36 ms |
6852 KB |
Output is correct |
30 |
Correct |
5 ms |
6852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
2008 KB |
Output is correct |
2 |
Correct |
24 ms |
2524 KB |
Output is correct |
3 |
Correct |
62 ms |
3328 KB |
Output is correct |
4 |
Correct |
54 ms |
4140 KB |
Output is correct |
5 |
Correct |
77 ms |
5416 KB |
Output is correct |
6 |
Correct |
50 ms |
5804 KB |
Output is correct |
7 |
Correct |
12 ms |
5804 KB |
Output is correct |
8 |
Correct |
50 ms |
5892 KB |
Output is correct |
9 |
Correct |
123 ms |
5892 KB |
Output is correct |
10 |
Correct |
71 ms |
6028 KB |
Output is correct |
11 |
Correct |
2 ms |
6028 KB |
Output is correct |
12 |
Correct |
2 ms |
6088 KB |
Output is correct |
13 |
Correct |
2 ms |
6104 KB |
Output is correct |
14 |
Correct |
4 ms |
6236 KB |
Output is correct |
15 |
Correct |
3 ms |
6236 KB |
Output is correct |
16 |
Correct |
3 ms |
6236 KB |
Output is correct |
17 |
Correct |
3 ms |
6236 KB |
Output is correct |
18 |
Correct |
3 ms |
6236 KB |
Output is correct |
19 |
Correct |
3 ms |
6236 KB |
Output is correct |
20 |
Correct |
2 ms |
6236 KB |
Output is correct |
21 |
Correct |
3 ms |
6236 KB |
Output is correct |
22 |
Correct |
3 ms |
6236 KB |
Output is correct |
23 |
Correct |
3 ms |
6236 KB |
Output is correct |
24 |
Correct |
3 ms |
6236 KB |
Output is correct |
25 |
Correct |
3 ms |
6236 KB |
Output is correct |
26 |
Correct |
33 ms |
6628 KB |
Output is correct |
27 |
Correct |
91 ms |
6840 KB |
Output is correct |
28 |
Correct |
113 ms |
6852 KB |
Output is correct |
29 |
Correct |
183 ms |
6852 KB |
Output is correct |
30 |
Correct |
206 ms |
6852 KB |
Output is correct |
31 |
Correct |
85 ms |
6852 KB |
Output is correct |
32 |
Correct |
3 ms |
6852 KB |
Output is correct |
33 |
Correct |
57 ms |
6852 KB |
Output is correct |
34 |
Correct |
102 ms |
6852 KB |
Output is correct |
35 |
Correct |
13 ms |
6852 KB |
Output is correct |
36 |
Correct |
65 ms |
6852 KB |
Output is correct |
37 |
Correct |
83 ms |
6852 KB |
Output is correct |
38 |
Correct |
106 ms |
6852 KB |
Output is correct |
39 |
Correct |
36 ms |
6852 KB |
Output is correct |
40 |
Correct |
5 ms |
6852 KB |
Output is correct |
41 |
Correct |
195 ms |
6980 KB |
Output is correct |
42 |
Correct |
141 ms |
6980 KB |
Output is correct |
43 |
Correct |
149 ms |
6980 KB |
Output is correct |
44 |
Correct |
134 ms |
8496 KB |
Output is correct |
45 |
Correct |
137 ms |
8496 KB |
Output is correct |
46 |
Correct |
241 ms |
8616 KB |
Output is correct |
47 |
Correct |
126 ms |
8616 KB |
Output is correct |
48 |
Correct |
144 ms |
8616 KB |
Output is correct |
49 |
Correct |
124 ms |
8616 KB |
Output is correct |
50 |
Correct |
569 ms |
8716 KB |
Output is correct |
51 |
Correct |
601 ms |
8740 KB |
Output is correct |
52 |
Correct |
568 ms |
8740 KB |
Output is correct |
53 |
Correct |
606 ms |
8740 KB |
Output is correct |
54 |
Correct |
556 ms |
8740 KB |
Output is correct |
55 |
Correct |
631 ms |
8740 KB |
Output is correct |
56 |
Correct |
542 ms |
8740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
476 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
476 KB |
Output is correct |
5 |
Correct |
2 ms |
496 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
552 KB |
Output is correct |
8 |
Correct |
2 ms |
552 KB |
Output is correct |
9 |
Correct |
88 ms |
2008 KB |
Output is correct |
10 |
Correct |
24 ms |
2524 KB |
Output is correct |
11 |
Correct |
62 ms |
3328 KB |
Output is correct |
12 |
Correct |
54 ms |
4140 KB |
Output is correct |
13 |
Correct |
77 ms |
5416 KB |
Output is correct |
14 |
Correct |
50 ms |
5804 KB |
Output is correct |
15 |
Correct |
12 ms |
5804 KB |
Output is correct |
16 |
Correct |
50 ms |
5892 KB |
Output is correct |
17 |
Correct |
123 ms |
5892 KB |
Output is correct |
18 |
Correct |
71 ms |
6028 KB |
Output is correct |
19 |
Correct |
2 ms |
6028 KB |
Output is correct |
20 |
Correct |
2 ms |
6088 KB |
Output is correct |
21 |
Correct |
2 ms |
6104 KB |
Output is correct |
22 |
Correct |
4 ms |
6236 KB |
Output is correct |
23 |
Correct |
3 ms |
6236 KB |
Output is correct |
24 |
Correct |
3 ms |
6236 KB |
Output is correct |
25 |
Correct |
3 ms |
6236 KB |
Output is correct |
26 |
Correct |
3 ms |
6236 KB |
Output is correct |
27 |
Correct |
3 ms |
6236 KB |
Output is correct |
28 |
Correct |
2 ms |
6236 KB |
Output is correct |
29 |
Correct |
3 ms |
6236 KB |
Output is correct |
30 |
Correct |
3 ms |
6236 KB |
Output is correct |
31 |
Correct |
3 ms |
6236 KB |
Output is correct |
32 |
Correct |
3 ms |
6236 KB |
Output is correct |
33 |
Correct |
3 ms |
6236 KB |
Output is correct |
34 |
Correct |
33 ms |
6628 KB |
Output is correct |
35 |
Correct |
91 ms |
6840 KB |
Output is correct |
36 |
Correct |
113 ms |
6852 KB |
Output is correct |
37 |
Correct |
183 ms |
6852 KB |
Output is correct |
38 |
Correct |
206 ms |
6852 KB |
Output is correct |
39 |
Correct |
85 ms |
6852 KB |
Output is correct |
40 |
Correct |
3 ms |
6852 KB |
Output is correct |
41 |
Correct |
57 ms |
6852 KB |
Output is correct |
42 |
Correct |
102 ms |
6852 KB |
Output is correct |
43 |
Correct |
13 ms |
6852 KB |
Output is correct |
44 |
Correct |
65 ms |
6852 KB |
Output is correct |
45 |
Correct |
83 ms |
6852 KB |
Output is correct |
46 |
Correct |
106 ms |
6852 KB |
Output is correct |
47 |
Correct |
36 ms |
6852 KB |
Output is correct |
48 |
Correct |
5 ms |
6852 KB |
Output is correct |
49 |
Correct |
195 ms |
6980 KB |
Output is correct |
50 |
Correct |
141 ms |
6980 KB |
Output is correct |
51 |
Correct |
149 ms |
6980 KB |
Output is correct |
52 |
Correct |
134 ms |
8496 KB |
Output is correct |
53 |
Correct |
137 ms |
8496 KB |
Output is correct |
54 |
Correct |
241 ms |
8616 KB |
Output is correct |
55 |
Correct |
126 ms |
8616 KB |
Output is correct |
56 |
Correct |
144 ms |
8616 KB |
Output is correct |
57 |
Correct |
124 ms |
8616 KB |
Output is correct |
58 |
Correct |
569 ms |
8716 KB |
Output is correct |
59 |
Correct |
601 ms |
8740 KB |
Output is correct |
60 |
Correct |
568 ms |
8740 KB |
Output is correct |
61 |
Correct |
606 ms |
8740 KB |
Output is correct |
62 |
Correct |
556 ms |
8740 KB |
Output is correct |
63 |
Correct |
631 ms |
8740 KB |
Output is correct |
64 |
Correct |
542 ms |
8740 KB |
Output is correct |
65 |
Correct |
2 ms |
8740 KB |
Output is correct |
66 |
Incorrect |
2 ms |
8740 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |