Problem Description
Problem Analysis
Originally, I intended to solve it by checking whether a linear equation in two variables has integer solutions.
So I wrote the WA version…
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| #include<stdio.h>
int gcd(int a,int b) {
if(b==0)
return a;
else
return gcd(b,a%b);
}
int main() {
int T;
scanf("%d",&T);
while(T--) {
int n,m;
scanf("%d %d",&n,&m);
int ta=180*n-360;
int tb=180*m-360;
if((360*n*m)%gcd(ta,tb)==0)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
//WA原因:解可能为负数
|
Because I didn’t consider that although integer solutions exist,
the integer solutions may be negative,
so it got WA.
AC code written based on the editorial:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| #include<stdio.h>
int main() {
int T;
scanf("%d",&T);
while(T--) {
int n,m;
scanf("%d %d",&n,&m);
if(n==3||n==4||n==6||m==3||m==4||m==6||(n==5&&m==10)||(n==10&&m==5))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
|
Maybe I could have solved it before learning the Extended Euclidean Algorithm,
but the more I learned, the more complicated I made it.
Problem URL:HDU 5660 jrMz and angles