E: Graph

本文探讨了如何判断是否能仅用尺规作出正多边形的问题,并介绍了与之相关的数学背景——费马素数。通过理解费马素数的概念及尺规作图的限制条件,给出了具体的实现算法。

题目描述

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


看第一眼就知道是数学题,可是自己没有推出公式来啊,o(︶︿︶)o 唉。百度题解才发现,原来是费马数,又学了点新东西。。
下面是关于费马数的一点东西,分享一下啦  :http://zh.wikipedia.org/wiki/%E8%B2%BB%E9%A6%AC%E8%B3%AA%E6%95%B8
这道题知道下面这个定理就能轻松的A掉了:

定理

高斯证明了:可以用尺规(指直尺圆规)画出正n边形的充要条件是n是2的幂乘以费马素数的积。

AC代码:
#include<stdio.h>
#include<string.h>
int main()
{
    //freopen("in.txt","r",stdin);
    int f[5]={3,5,17,257,65537};
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        while(n%2==0)
        {
            n/=2;
        }
        if(n%f[0]==0)
            n/=f[0];
        if(n%f[1]==0)
            n/=f[1];
        if(n%f[2]==0)
            n/=f[2];
        if(n%f[3]==0)
            n/=f[3];
        if(n%f[4]==0)
            n/=f[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、付费专栏及课程。

余额充值