Graph
时间限制: 1 Sec 内存限制: 128 MB提交: 37 解决: 7
[ 提交][ 状态][ 论坛]
题目描述
Your task is to judge whether a regular polygon can be drawn only by straightedge and compass.
The length of the straightedge is infinite.
The width of the compass is infinite.
The straightedge does not have scale.
输入
There are several test cases. Each test case contains a positive integer n (3<=n<=10^9). The input will be ended by the End Of File.
输出
If the regular polygon with n sides can be drawn only by straightedge and compass, output YES in one line, otherwise, output NO in one line.
样例输入
3
4
5
6
7
样例输出
YES
YES
YES
YES
NO
提示
来源
纯粹的费马数与尺规作图
高斯证明了:正多边形的边数为2^n与边数为不同的费马数的乘积形式的正多边形才可以在圆内用尺规画出。
#include<cstdio>
using namespace std;
int a[5]={(1<<1)+1,(1<<2)+1,(1<<4)+1,(1<<8)+1,(1<<16)+1}; //费马数
int main(){
long long n;
while(scanf("%lld",&n)!=EOF){
while(n%2==0)
n/=2;
int i=0;
if(n%a[0]==0)
n/=a[0];
if(n%a[1]==0)
n/=a[1];
if(n%a[2]==0)
n/=a[2];
if(n%a[3]==0)
n/=a[3];
if(n%a[4]==0)
n/=a[4];
if(n==1)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}