#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
ll n,k,p,u,ans,i,j,v,x1[100005],x2[100005],y[100005],y2[100005],ans1,ans2,t,q;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>k;
for(i=1;i<=k;i++)
{
cin>>x1[i]>>y[i]>>x2[i]>>y2[i];
ll kent1=0,kent2=0,zuyg1=0,zuyg2=0,t1,t2;
t1=x2[i]-x1[i]+1;
if(x1[i]%2==0)
{
zuyg1+=(t1+1)/2;
kent1+=t1/2;
}
else
{
kent1+=(t1+1)/2;
zuyg1+=t1/2;
}
t2=y2[i]-y[i]+1;
if(y[i]%2==0)
{
zuyg2+=(t2+1)/2;
kent2+=t2/2;
}
else
{
kent2+=(t2+1)/2;
zuyg2+=t2/2;
}
u+=kent1*kent2+zuyg1*zuyg2;
v+=kent1*zuyg2+zuyg1*kent2;
}
if(n%2==0)
p=n*n/2;
else
p=n*n/2+1;
q=n*n/2;
ans=min(p-u+v,q-v+u);
for(j=2;j<=n;j++)
{
if(n%j==0)
{
u=0;
v=0;
t=n/j;
for(i=1;i<=k;i++)
{
ll kent1=0,kent2=0,zuyg1=0,zuyg2=0,t1,t2,arajin1=0,arajin2=0,verjin1=0,verjin2=0,g;
arajin1=(x1[i]-1)/t+1;
if(x2[i]%t==0)
verjin1=x2[i]/t;
else
verjin1=x2[i]/t+1;
arajin2=(y[i]-1)/t+1;
if(y2[i]%t==0)
verjin2=y2[i]/t;
else
verjin2=y2[i]/t+1;
if(arajin1==verjin1)
{
if(arajin1%2==0)
zuyg1+=x2[i]-x1[i]+1;
else
kent1=x2[i]-x1[i]+1;
}
else
{
if((x1[i]-1)%t==0)
{
if(arajin1%2==0)
zuyg1+=t;
else
kent1+=t;
}
else
{
t1=t-(x1[i]-1)%t;
if(arajin1%2==0)
zuyg1+=t1;
else
kent1+=t1;
}
arajin1++;
if(x2[i]%t==0)
{
if(verjin1%2==0)
zuyg1+=t;
else
kent1+=t;
}
else
{
t1=x2[i]%t;
if(verjin1%2==0)
zuyg1+=t1;
else
kent1+=t1;
}
verjin1--;
g=verjin1-arajin1+1;
if(arajin1%2==0)
{
t1=(g+1)/2;
t2=g/2;
}
else
{
t1=g/2;
t2=(g+1)/2;
}
zuyg1+=t1*t;
kent1+=t2*t;
}
if(arajin2==verjin2)
{
if(arajin2%2==0)
zuyg2+=y2[i]-y[i]+1;
else
kent2=y2[i]-y[i]+1;
}
else
{
if((y[i]-1)%t==0)
{
if(arajin2%2==0)
zuyg2+=t;
else
kent2+=t;
}
else
{
t1=t-(y[i]-1)%t;
if(arajin2%2==0)
zuyg2+=t1;
else
kent2+=t1;
}
arajin2++;
if(y2[i]%t==0)
{
if(verjin2%2==0)
zuyg2+=t;
else
kent2+=t;
}
else
{
t1=y2[i]%t;
if(verjin2%2==0)
zuyg2+=t1;
else
kent2+=t1;
}
verjin2--;
g=verjin2-arajin2+1;
if(arajin2%2==0)
{
t1=(g+1)/2;
t2=g/2;
}
else
{
t1=g/2;
t2=(g+1)/2;
}
zuyg2+=t1*t;
kent2+=t2*t;
}
u+=kent1*kent2+zuyg1*zuyg2;
v+=kent1*zuyg2+zuyg1*kent2;
}
q=n/j;
if(j%2==1)
ans1=j*j/2+1;
else
ans1=j*j/2;
ans1=ans1*q*q;
ans1=ans1-u+v;
ans2=j*j/2;
ans2=ans2*q*q;
ans2=ans2-v+u;
ans=min(ans,ans2);
ans=min(ans,ans1);
}
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
2424 KB |
Output is correct |
2 |
Correct |
11 ms |
1016 KB |
Output is correct |
3 |
Correct |
23 ms |
1656 KB |
Output is correct |
4 |
Correct |
24 ms |
1912 KB |
Output is correct |
5 |
Correct |
31 ms |
2168 KB |
Output is correct |
6 |
Correct |
20 ms |
1532 KB |
Output is correct |
7 |
Correct |
6 ms |
760 KB |
Output is correct |
8 |
Correct |
21 ms |
1532 KB |
Output is correct |
9 |
Correct |
52 ms |
3420 KB |
Output is correct |
10 |
Correct |
30 ms |
2140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
18 ms |
1656 KB |
Output is correct |
17 |
Correct |
38 ms |
4088 KB |
Output is correct |
18 |
Correct |
56 ms |
4472 KB |
Output is correct |
19 |
Correct |
184 ms |
4220 KB |
Output is correct |
20 |
Correct |
205 ms |
4572 KB |
Output is correct |
21 |
Correct |
36 ms |
3932 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
36 ms |
2412 KB |
Output is correct |
24 |
Correct |
53 ms |
4216 KB |
Output is correct |
25 |
Correct |
9 ms |
760 KB |
Output is correct |
26 |
Correct |
35 ms |
3064 KB |
Output is correct |
27 |
Correct |
48 ms |
3576 KB |
Output is correct |
28 |
Correct |
55 ms |
4344 KB |
Output is correct |
29 |
Correct |
16 ms |
1912 KB |
Output is correct |
30 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
2424 KB |
Output is correct |
2 |
Correct |
11 ms |
1016 KB |
Output is correct |
3 |
Correct |
23 ms |
1656 KB |
Output is correct |
4 |
Correct |
24 ms |
1912 KB |
Output is correct |
5 |
Correct |
31 ms |
2168 KB |
Output is correct |
6 |
Correct |
20 ms |
1532 KB |
Output is correct |
7 |
Correct |
6 ms |
760 KB |
Output is correct |
8 |
Correct |
21 ms |
1532 KB |
Output is correct |
9 |
Correct |
52 ms |
3420 KB |
Output is correct |
10 |
Correct |
30 ms |
2140 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
380 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
18 ms |
1656 KB |
Output is correct |
27 |
Correct |
38 ms |
4088 KB |
Output is correct |
28 |
Correct |
56 ms |
4472 KB |
Output is correct |
29 |
Correct |
184 ms |
4220 KB |
Output is correct |
30 |
Correct |
205 ms |
4572 KB |
Output is correct |
31 |
Correct |
36 ms |
3932 KB |
Output is correct |
32 |
Correct |
3 ms |
376 KB |
Output is correct |
33 |
Correct |
36 ms |
2412 KB |
Output is correct |
34 |
Correct |
53 ms |
4216 KB |
Output is correct |
35 |
Correct |
9 ms |
760 KB |
Output is correct |
36 |
Correct |
35 ms |
3064 KB |
Output is correct |
37 |
Correct |
48 ms |
3576 KB |
Output is correct |
38 |
Correct |
55 ms |
4344 KB |
Output is correct |
39 |
Correct |
16 ms |
1912 KB |
Output is correct |
40 |
Correct |
4 ms |
504 KB |
Output is correct |
41 |
Correct |
160 ms |
3960 KB |
Output is correct |
42 |
Correct |
65 ms |
4368 KB |
Output is correct |
43 |
Correct |
98 ms |
3960 KB |
Output is correct |
44 |
Correct |
62 ms |
4252 KB |
Output is correct |
45 |
Correct |
53 ms |
4444 KB |
Output is correct |
46 |
Correct |
180 ms |
4472 KB |
Output is correct |
47 |
Correct |
47 ms |
4088 KB |
Output is correct |
48 |
Correct |
81 ms |
4216 KB |
Output is correct |
49 |
Correct |
57 ms |
4080 KB |
Output is correct |
50 |
Correct |
766 ms |
4288 KB |
Output is correct |
51 |
Correct |
819 ms |
4600 KB |
Output is correct |
52 |
Correct |
762 ms |
4284 KB |
Output is correct |
53 |
Correct |
817 ms |
4344 KB |
Output is correct |
54 |
Correct |
755 ms |
4244 KB |
Output is correct |
55 |
Correct |
844 ms |
4652 KB |
Output is correct |
56 |
Correct |
725 ms |
4216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
35 ms |
2424 KB |
Output is correct |
10 |
Correct |
11 ms |
1016 KB |
Output is correct |
11 |
Correct |
23 ms |
1656 KB |
Output is correct |
12 |
Correct |
24 ms |
1912 KB |
Output is correct |
13 |
Correct |
31 ms |
2168 KB |
Output is correct |
14 |
Correct |
20 ms |
1532 KB |
Output is correct |
15 |
Correct |
6 ms |
760 KB |
Output is correct |
16 |
Correct |
21 ms |
1532 KB |
Output is correct |
17 |
Correct |
52 ms |
3420 KB |
Output is correct |
18 |
Correct |
30 ms |
2140 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
380 KB |
Output is correct |
31 |
Correct |
3 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
3 ms |
376 KB |
Output is correct |
34 |
Correct |
18 ms |
1656 KB |
Output is correct |
35 |
Correct |
38 ms |
4088 KB |
Output is correct |
36 |
Correct |
56 ms |
4472 KB |
Output is correct |
37 |
Correct |
184 ms |
4220 KB |
Output is correct |
38 |
Correct |
205 ms |
4572 KB |
Output is correct |
39 |
Correct |
36 ms |
3932 KB |
Output is correct |
40 |
Correct |
3 ms |
376 KB |
Output is correct |
41 |
Correct |
36 ms |
2412 KB |
Output is correct |
42 |
Correct |
53 ms |
4216 KB |
Output is correct |
43 |
Correct |
9 ms |
760 KB |
Output is correct |
44 |
Correct |
35 ms |
3064 KB |
Output is correct |
45 |
Correct |
48 ms |
3576 KB |
Output is correct |
46 |
Correct |
55 ms |
4344 KB |
Output is correct |
47 |
Correct |
16 ms |
1912 KB |
Output is correct |
48 |
Correct |
4 ms |
504 KB |
Output is correct |
49 |
Correct |
160 ms |
3960 KB |
Output is correct |
50 |
Correct |
65 ms |
4368 KB |
Output is correct |
51 |
Correct |
98 ms |
3960 KB |
Output is correct |
52 |
Correct |
62 ms |
4252 KB |
Output is correct |
53 |
Correct |
53 ms |
4444 KB |
Output is correct |
54 |
Correct |
180 ms |
4472 KB |
Output is correct |
55 |
Correct |
47 ms |
4088 KB |
Output is correct |
56 |
Correct |
81 ms |
4216 KB |
Output is correct |
57 |
Correct |
57 ms |
4080 KB |
Output is correct |
58 |
Correct |
766 ms |
4288 KB |
Output is correct |
59 |
Correct |
819 ms |
4600 KB |
Output is correct |
60 |
Correct |
762 ms |
4284 KB |
Output is correct |
61 |
Correct |
817 ms |
4344 KB |
Output is correct |
62 |
Correct |
755 ms |
4244 KB |
Output is correct |
63 |
Correct |
844 ms |
4652 KB |
Output is correct |
64 |
Correct |
725 ms |
4216 KB |
Output is correct |
65 |
Correct |
2 ms |
376 KB |
Output is correct |
66 |
Correct |
2 ms |
376 KB |
Output is correct |
67 |
Correct |
837 ms |
5496 KB |
Output is correct |
68 |
Correct |
829 ms |
5496 KB |
Output is correct |
69 |
Correct |
715 ms |
4880 KB |
Output is correct |
70 |
Correct |
771 ms |
5468 KB |
Output is correct |
71 |
Correct |
776 ms |
5300 KB |
Output is correct |
72 |
Correct |
747 ms |
5240 KB |
Output is correct |
73 |
Correct |
752 ms |
5112 KB |
Output is correct |
74 |
Correct |
822 ms |
5596 KB |
Output is correct |
75 |
Correct |
769 ms |
5368 KB |
Output is correct |
76 |
Correct |
823 ms |
5624 KB |
Output is correct |
77 |
Correct |
145 ms |
5880 KB |
Output is correct |
78 |
Correct |
64 ms |
5308 KB |
Output is correct |
79 |
Correct |
105 ms |
5020 KB |
Output is correct |
80 |
Correct |
108 ms |
5368 KB |
Output is correct |
81 |
Correct |
101 ms |
4856 KB |
Output is correct |
82 |
Correct |
89 ms |
5496 KB |
Output is correct |
83 |
Correct |
71 ms |
5112 KB |
Output is correct |
84 |
Correct |
497 ms |
5716 KB |
Output is correct |
85 |
Correct |
883 ms |
5832 KB |
Output is correct |
86 |
Correct |
4 ms |
376 KB |
Output is correct |
87 |
Correct |
4 ms |
376 KB |
Output is correct |
88 |
Correct |
911 ms |
5884 KB |
Output is correct |
89 |
Correct |
168 ms |
1400 KB |
Output is correct |
90 |
Correct |
3 ms |
376 KB |
Output is correct |