Regular polygon Interior angles

534 Views Asked by At

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() {
 // your code goes here
  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

1

There are 1 best solutions below

1
On BEST ANSWER

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. :)