Alice and Bob

Alice and Bob

时间限制: 1000 ms  |  内存限制: 65535 KB
难度: 2
描述
As we all know, math is very important,so we must learn math well.
Alice and Bob are good friends.Today Alice ask Bob to help her judge whether a number is perfect or not. Perfect number is a kind of number like this:

First, 1 and 3 are perfect number.
Then if a and b are perfect numbers, 2+ab+2a+2b is also a perfect number.

For example, 1 and 3 are perfect numbers,  so 2+3+2+6 = 13 is perfect number.

If Bob can't help Alice,  Alice will be sad and Bob will be much more sad. So Bob must solve the problem to maintain their friendship. Can you help Bob to solve the problem?

输入
It contains multiple test cases.
Each test case contains one line.
Each line contains an interger n, 1 <= n <= 10^9.
输出
For each test case, if n is a perfect number, output “YES”, otherwise output “NO”.
样例输入
1
6
23
样例输出
YES
NO
YES
由2+ab+2a+2b=(a+2)*(b+2)-2可知,(perfect number+2)满足被(a+2)和(b+2)整除。而1+2=3,3+2=5,故对于输入的数进行/3、/5的操作直到不能继续,如果最后得1,表示这个数是perfect number
#include<stdio.h>
int main()
{
    int n;
    while(scanf("%d",&n)!=-1)
    {
         int k;
         k=n+2;
         while(k%3==0)
         {
             k=k/3;
         }
         while(k%5==0)
         {
             k=k/5;
         }
         if(k==1)
         {
             printf("YES\n");
         }
         else
         {
             printf("NO\n");
         }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值