// Muallif: Mansuraliyev Husanboy Murotali o'g'li >> NamPS
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const double PI=3.1415926535897932384626433832795;
// 0-9 >> 48-57; A-Z>>65-90 and a-z>>97-122 respectively;
int main(){
ios;
ll n,q; cin>>n>>q;
vector<ll> a;
a.push_back(1ll);
ll b=sqrt(n);
for(ll i=2;i<sqrt(n);i++){
if(n%i==0){
a.push_back(i); a.push_back(n/i);
}
}
if(b*b==n){
a.push_back(b);
}
vector<ll> ans,ans2;
ll sz=a.size();
for(auto u:a){
ll x=n/u;
if(x%2ll==0){
ans.push_back((n*n)/2ll);
ans2.push_back((n*n)/2ll);
}else{
ll k=(n*n-u*u)/2ll+u*u;
ans.push_back(k);
ans2.push_back(n*n-k);
}
}
while(q--){
ll x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
for(int i=0;i<sz;i++){
ll u=a[i];
/*ll x=n/u;
ll black=0ll,white=0ll;
ll tx2=x2-x2%u,tx1=x1-(x1%u==0ll||x1%u==1ll?u:x1%u)+u+(x1%u==1ll||u==1ll?0ll:1ll),ty1=y1-(y1%u==0ll||y1%u==1ll?u:y1%u)+u+(y1%u==1||u==1ll?0ll:1ll),ty2=y2-y2%u;
//cout<<u<<": "<<tx1<<' '<<ty1<<' '<<tx2<<' '<<ty2<<endl;
if(tx1<=tx2&&ty1<=ty2){
}else{
}*/
ll x=(x1+u-1ll)/u,y=(y1+u-1ll)/u;
//cout<<u<<": "<<x<<' '<<y<<">> ";
if((x+y)%2==0){
ans[i]--; ans2[i]++;//cout<<ans[i]<<endl;
}else{
ans[i]++; ans2[i]--;//cout<<ans[i]<<endl;
}
}
}
ll mn=1e18;
for(int i=0;i<sz;i++){
//cout<<ans[i]<<' '<<ans2[i]<<endl;
mn=min(mn,min(ans[i],ans2[i]));
}
cout<<mn;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
312 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1732 KB |
Output is correct |
2 |
Correct |
8 ms |
588 KB |
Output is correct |
3 |
Correct |
12 ms |
1200 KB |
Output is correct |
4 |
Correct |
14 ms |
1064 KB |
Output is correct |
5 |
Correct |
18 ms |
1556 KB |
Output is correct |
6 |
Correct |
11 ms |
1056 KB |
Output is correct |
7 |
Correct |
3 ms |
460 KB |
Output is correct |
8 |
Correct |
12 ms |
1060 KB |
Output is correct |
9 |
Correct |
33 ms |
2336 KB |
Output is correct |
10 |
Correct |
16 ms |
1464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
13 ms |
716 KB |
Output is correct |
17 |
Correct |
23 ms |
1552 KB |
Output is correct |
18 |
Correct |
27 ms |
1824 KB |
Output is correct |
19 |
Correct |
63 ms |
1684 KB |
Output is correct |
20 |
Correct |
60 ms |
1884 KB |
Output is correct |
21 |
Correct |
20 ms |
1604 KB |
Output is correct |
22 |
Correct |
1 ms |
320 KB |
Output is correct |
23 |
Correct |
15 ms |
916 KB |
Output is correct |
24 |
Correct |
24 ms |
1704 KB |
Output is correct |
25 |
Correct |
3 ms |
332 KB |
Output is correct |
26 |
Correct |
16 ms |
1180 KB |
Output is correct |
27 |
Correct |
21 ms |
1320 KB |
Output is correct |
28 |
Correct |
31 ms |
1808 KB |
Output is correct |
29 |
Correct |
9 ms |
844 KB |
Output is correct |
30 |
Correct |
2 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1732 KB |
Output is correct |
2 |
Correct |
8 ms |
588 KB |
Output is correct |
3 |
Correct |
12 ms |
1200 KB |
Output is correct |
4 |
Correct |
14 ms |
1064 KB |
Output is correct |
5 |
Correct |
18 ms |
1556 KB |
Output is correct |
6 |
Correct |
11 ms |
1056 KB |
Output is correct |
7 |
Correct |
3 ms |
460 KB |
Output is correct |
8 |
Correct |
12 ms |
1060 KB |
Output is correct |
9 |
Correct |
33 ms |
2336 KB |
Output is correct |
10 |
Correct |
16 ms |
1464 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
320 KB |
Output is correct |
26 |
Correct |
13 ms |
716 KB |
Output is correct |
27 |
Correct |
23 ms |
1552 KB |
Output is correct |
28 |
Correct |
27 ms |
1824 KB |
Output is correct |
29 |
Correct |
63 ms |
1684 KB |
Output is correct |
30 |
Correct |
60 ms |
1884 KB |
Output is correct |
31 |
Correct |
20 ms |
1604 KB |
Output is correct |
32 |
Correct |
1 ms |
320 KB |
Output is correct |
33 |
Correct |
15 ms |
916 KB |
Output is correct |
34 |
Correct |
24 ms |
1704 KB |
Output is correct |
35 |
Correct |
3 ms |
332 KB |
Output is correct |
36 |
Correct |
16 ms |
1180 KB |
Output is correct |
37 |
Correct |
21 ms |
1320 KB |
Output is correct |
38 |
Correct |
31 ms |
1808 KB |
Output is correct |
39 |
Correct |
9 ms |
844 KB |
Output is correct |
40 |
Correct |
2 ms |
320 KB |
Output is correct |
41 |
Correct |
60 ms |
2196 KB |
Output is correct |
42 |
Correct |
32 ms |
2468 KB |
Output is correct |
43 |
Correct |
39 ms |
2200 KB |
Output is correct |
44 |
Correct |
31 ms |
2448 KB |
Output is correct |
45 |
Correct |
29 ms |
2584 KB |
Output is correct |
46 |
Correct |
68 ms |
2448 KB |
Output is correct |
47 |
Correct |
27 ms |
2320 KB |
Output is correct |
48 |
Correct |
34 ms |
2360 KB |
Output is correct |
49 |
Correct |
27 ms |
2192 KB |
Output is correct |
50 |
Correct |
197 ms |
2452 KB |
Output is correct |
51 |
Correct |
225 ms |
2588 KB |
Output is correct |
52 |
Correct |
193 ms |
2332 KB |
Output is correct |
53 |
Correct |
222 ms |
2588 KB |
Output is correct |
54 |
Correct |
201 ms |
2372 KB |
Output is correct |
55 |
Correct |
230 ms |
2596 KB |
Output is correct |
56 |
Correct |
192 ms |
2336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
312 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
312 KB |
Output is correct |
9 |
Correct |
19 ms |
1732 KB |
Output is correct |
10 |
Correct |
8 ms |
588 KB |
Output is correct |
11 |
Correct |
12 ms |
1200 KB |
Output is correct |
12 |
Correct |
14 ms |
1064 KB |
Output is correct |
13 |
Correct |
18 ms |
1556 KB |
Output is correct |
14 |
Correct |
11 ms |
1056 KB |
Output is correct |
15 |
Correct |
3 ms |
460 KB |
Output is correct |
16 |
Correct |
12 ms |
1060 KB |
Output is correct |
17 |
Correct |
33 ms |
2336 KB |
Output is correct |
18 |
Correct |
16 ms |
1464 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
312 KB |
Output is correct |
21 |
Correct |
1 ms |
316 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
320 KB |
Output is correct |
34 |
Correct |
13 ms |
716 KB |
Output is correct |
35 |
Correct |
23 ms |
1552 KB |
Output is correct |
36 |
Correct |
27 ms |
1824 KB |
Output is correct |
37 |
Correct |
63 ms |
1684 KB |
Output is correct |
38 |
Correct |
60 ms |
1884 KB |
Output is correct |
39 |
Correct |
20 ms |
1604 KB |
Output is correct |
40 |
Correct |
1 ms |
320 KB |
Output is correct |
41 |
Correct |
15 ms |
916 KB |
Output is correct |
42 |
Correct |
24 ms |
1704 KB |
Output is correct |
43 |
Correct |
3 ms |
332 KB |
Output is correct |
44 |
Correct |
16 ms |
1180 KB |
Output is correct |
45 |
Correct |
21 ms |
1320 KB |
Output is correct |
46 |
Correct |
31 ms |
1808 KB |
Output is correct |
47 |
Correct |
9 ms |
844 KB |
Output is correct |
48 |
Correct |
2 ms |
320 KB |
Output is correct |
49 |
Correct |
60 ms |
2196 KB |
Output is correct |
50 |
Correct |
32 ms |
2468 KB |
Output is correct |
51 |
Correct |
39 ms |
2200 KB |
Output is correct |
52 |
Correct |
31 ms |
2448 KB |
Output is correct |
53 |
Correct |
29 ms |
2584 KB |
Output is correct |
54 |
Correct |
68 ms |
2448 KB |
Output is correct |
55 |
Correct |
27 ms |
2320 KB |
Output is correct |
56 |
Correct |
34 ms |
2360 KB |
Output is correct |
57 |
Correct |
27 ms |
2192 KB |
Output is correct |
58 |
Correct |
197 ms |
2452 KB |
Output is correct |
59 |
Correct |
225 ms |
2588 KB |
Output is correct |
60 |
Correct |
193 ms |
2332 KB |
Output is correct |
61 |
Correct |
222 ms |
2588 KB |
Output is correct |
62 |
Correct |
201 ms |
2372 KB |
Output is correct |
63 |
Correct |
230 ms |
2596 KB |
Output is correct |
64 |
Correct |
192 ms |
2336 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |