regular polygon can be drawn only by straightedge and compass

来源:互联网 发布:网络it需要什么学历 编辑:程序博客网 时间:2024/04/23 21:15

Description

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.

Input

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.

Output

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.

Sample Input 

34567

Sample Output

YESYESYESYESNO

分析:正 N 边形可用直尺和圆规作出,当且仅当 N  =  2m p1 p2 ...... pk

其中 p1, p2, ......, pk  是互异的费马素数,即形如  的素数。

迄今为止只找到了 F0  = 3F1  = 5,  F2  = 17,  F3  = 257,  F4  = 65537 这五个费马素数

#include <cstdio>const int fima[] = {3, 5, 17, 257, 65537};int main(){int x;while(~scanf("%d", &x)) {int yes = 0;for(int i=0; i<5; i++) if(x%fima[i]==0) x/=fima[i];        for(int i=0; i<30; i++) if((x==(1<<i))) { yes = 1; break; }        printf("%s\n", yes?"YES":"NO");}    return 0;}




1 0
原创粉丝点击