jrMz and angles
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 183 Accepted Submission(s): 124
Problem Description
jrMz has two types of angles, one type of angle is an interior angle of
n
-sided regular polygon, and the other type of angle is an interior angle of
m
-sided regular polygon. jrMz wants to use them to make up an angle of 360 degrees, which means, jrMz needs to choose some or none of the angles which belong to the first type and some or none of the angles which belong to the second type so that the sum value of the angles chosen equals 360 degrees. But jrMz doesn’t know whether it is possible, can you help him?
Input
The first line contains an integer
T(1≤T≤10)
——The number of the test cases.
For each test case, the only line contains two integers n,m(1≤n,m≤100) with a white space separated.
For each test case, the only line contains two integers n,m(1≤n,m≤100) with a white space separated.
Output
For each test case, the only line contains a integer that is the answer.
Sample Input
3
4 8
3 10
5 8
Sample Output
Yes
Yes
No
3
4 8
3 10
5 8
Sample Output
Yes
Yes
No
思路:
暴力枚举。
AC代码:
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
int neijiaohe=(n-2)*180;
int neijiaohe2=(m-2)*180;
int a=neijiaohe/n;
int b=neijiaohe2/m;
int ok=0;
for(int i=0;;i++)
{
if(i*a>360)break;
for(int j=0;;j++)
{
if(j*b+i*a>360)break;
if(a*i+b*j==360)
{
ok=1;
break;
}
}
if(ok==1)break;
}
if(ok==1)printf("Yes\n");
else printf("No\n");
}
}