E: Graph

来源:互联网 发布:宝宝店软件 编辑:程序博客网 时间:2024/04/29 00:05

题目描述

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.

样例输入

34567

样例输出

YESYESYESYESNO看第一眼就知道是数学题,可是自己没有推出公式来啊,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;}


0 0
原创粉丝点击