Graph(费马数与尺规作图)

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

提示

来源

辽宁省赛2014

纯粹的费马数与尺规作图

高斯证明了:正多边形的边数为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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值