哈理工OJ 1692【水题】

来源:互联网 发布:大数据英文怎么说 编辑:程序博客网 时间:2024/05/17 04:59

GiGi兔与numberTime Limit: 1000 MSMemory Limit: 32768 KTotal Submit: 111(47 users)Total Accepted: 52(44 users)Rating: Special Judge: NoDescription

 GiGi兔在玩她上一个游戏的时候想到了她很不喜欢的的3个数字:2, 3, 5。所以只和这3个数字有关(即素因子只包含2,3,5)的数她都不喜欢。比如:8=2*2*2,10=2*5,12=2*2*3,14=2*7,16=2*2*2*2。她不喜欢8,10,12,16,但是喜欢14,。因为14的一个素因子为7。现在给出一个数n,判断是否是GiGi兔喜欢的数字?

Input

输入包含多组测试数据。

每一行包含一个正整数n(1=<n<=100000)。

Output

每行包括一个字符串“YES”, 或者NO”。如果是她喜欢的输出YES”,否则输出NO”

Sample Input

1

4

6

7

Sample Output

YES

NO

NO

YES


思路很好形成的一个题,因为N并不大,所以我们采用暴力除因子数的方法来做,因为题干说只有2,3,5,因子数的输出NO,那么我们就把n包含的2,3,5全部除掉,就可以了~

#include<stdio.h>#include<string.h>#include<math.h>using namespace std;int main(){    int n;    while(~scanf("%d",&n))    {        if(n==1)        {            printf("YES\n");            continue;        }        while(1)        {            if(n%2!=0)            break;            else            n/=2;        }        if(n==1)        {            printf("NO\n");        }        else        {            while(1)            {                if(n%3!=0)                {                    break;                }                else                n/=3;            }            if(n==1)            {                printf("NO\n");            }            else            {                while(1)                {                    if(n%5!=0)                    break;                    else                    n/=5;                }                if(n==1)                {                    printf("NO\n");                }                else                {                    printf("YES\n");                }            }        }    }}











0 0
原创粉丝点击