Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
The first line of input contains an integer t (0 < t < 180) — the number of tests. Each of the following t lines contains a single integer a (0 < a < 180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
3 30 60 90
NO YES YES
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle .
In the second test case, the fence is a regular triangle, and in the last test case — a square.
正n边形角度:a=(180*i)/(i+2)。
这道题最重要的是要注意浮点型带来的误差
AC:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
if(n>=180||n<=0)
{
cout<<"NO"<<endl;
continue;
}
for(int i=1;i>0;i++)
{
if((double)(180.0*i)/(i+2)==n)
{
cout<<"YES"<<endl;
break;
}
if((double)(180.0*i)/(i+2)>n)
{
cout<<"NO"<<endl;
break;
}
}
}
}