Alice and Bob
来源:互联网 发布:蛙5火箭知乎 编辑:程序博客网 时间:2024/05/16 12:11
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”.
- 样例输入
1623
- 样例输出
YESNOYES
由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
- Alice and Bob
- 2683. Alice and Bob
- 1798. Alice and Bob
- hdu4268 Alice and Bob
- HDU4268 Alice and Bob
- Alice, Bob and Chocolate
- hdu4268 Alice and Bob
- A:Alice and Bob
- hdu4111 Alice and Bob
- Alice and Bob
- 1798[Bob and Alice]
- Alice and Bob 数学题
- Alice and Bob
- XTU_1168 Alice and Bob
- SOJ.Alice and Bob
- UPC2222: Alice and Bob
- F:Alice and Bob
- Alice and Bob
- HDU 5724 博弈,SG函数
- 【 Codeforces 615A】A. Bulbs
- Android之基于位置的服务
- WPF编程宝典读书笔记——第10章 资源(一)
- 取出一个字符串中字母出现的次数。如:字符串:"abcde%^kka27qoq" ,输出格式为: a(2)b(1)k(2)...
- Alice and Bob
- POJ 2406 Power Strings (kmp求循环节)
- Android中的事件分发和处理
- Android 补间动画
- SharedPreferences 监听变化Listener 的onSharedPreferenceChanged方法没有调用
- Iframe实现Ajax文件上传Servlet响应上传结果
- C#:网络通信(TCP)
- 第一章.对象导论之方法的重写和重载
- HDOJ 5744 Keep On Movin(最大化最短回文串长度)