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
-
代码实现:
-
#include<stdio.h>
int main()
{
int a;
while(scanf("%d",&a)!=EOF)
{
a+=2;
while(a%5==0)
a/=5;
while(a%3==0)
a/=3;
if(a==1)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
-
实现思路:根据题意知道,1和3是perfect number。由于2+ab+2a+2b =(a+2)*(b+2)-2,对于这个公式中,若a=b也成立,所以如果是perfect number+2应该能被3或者5整除。若整除后的结果为1则输出YES,否则为NO。
-
It contains multiple test cases.