Regular polygon Interior angles

I am to find if any given angle(say x)can be interior angle of regular polygon.In other words,is there a regular polygon which angles are equal to X.

I know the formula for sum of interior angles of polygon i.e (n-2)*180. I tried looping from sides 3 to 10000 and pushing back ((n-2)*180)/n and after this pre-computation i tried searching each given angles.Please see code if not clear

#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
vector<int>v;
for(int i=3;i<=1000;i++)
v.push_back(((180)*(i-2))/(i));
while(t--)
{
int a;
cin>>a;
if(find(v.begin(),v.end(),a)!=v.end())
puts("YES");
else
puts("NO");
}
return 0;
}


This is giving correct answer for some values but not all.

Is there any better(geometrical way) to do this ?

EDIT:-

I have seen the solution and it was something like true if (360%(180-x)==0) else false.I still can't get it(why 360%(180-x).Anybody please explain this or give different way

• v.push_back(((180)*(i-2))/(i)); should be v.push_back(((180)*(i-2))/double(i)); – Alexey Burdin May 1 '15 at 3:45
• Why double MR@AlexeyBurdin .Well even after type cating it is not giving correct answer. – chota bheem May 1 '15 at 3:53
• So the problem is "Determine if there is a regular polygon with interior angle strictly equal to that given integer degrees"? – Alexey Burdin May 1 '15 at 4:22
• possibly i am not clear enough.You can see this sir,codeforces.com/problemset/problem/270/A – chota bheem May 1 '15 at 4:25

Let $A,B$ be the consecutive vertices of a regular $n$-vertices polygon and $O$ be it's center.
$\angle AOB=\frac{360^{\circ}}{n}$, $\Delta AOB$ is isosceles, so $\angle OAB = \frac{180^{\circ} - \angle AOB}{2}$ and the interior angle $=2\angle OAB = x^{\circ}$ and $x$ is integer.
We are to find whether it could be an integer $n$ that gives that $x$.
$$180-\frac{360}{n}=x$$ $$\frac{360}{n}=180-x$$ $$n=\frac{360}{180-x}$$ So puts(360%(180-x)?"NO":"YES") should work. :)