Friend

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2073    Accepted Submission(s): 1046

Problem Description
Friend number are defined recursively as follows. (1) numbers 1 and 2 are friend number; (2) if a and b are friend numbers, so is ab+a+b; (3) only the numbers defined in (1) and (2) are friend number. Now your task is to judge whether an integer is a friend number.
 
Input
There are several lines in input, each line has a nunnegative integer a, 0<=a<=2^30.
 
Output
For the number a on each line of the input, if a is a friend number, output “YES!”, otherwise output “NO!”.
 
Sample Input
3 13121 12131
 
Sample Output
YES! YES! NO!
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  1905 2082 1073 1715 1257 
心塞的一题。。。。。。。
friend 数为ab+a+b,那么可以变成(a+1)(b+1)-1,只要给一个数加上1,然后判断他是否是由一系列2和一系列3组成的,
因为所有的数都是有(a+1)(b+1) ,2,3递推而来的。
#include <iostream>
#include <cstdio>
#define LL int
using namespace std; void solve(LL x)
{
while((x%)==)
{
x/=;
if(x==)
break;
}
while((x%)==)
{
x/=;
if(x==)
break;
}
if(x==)
printf("YES!\n");
else
printf("NO!\n");
}
int main()
{
LL x,T;
while(~scanf("%d",&x))
{
if(x== || x==)
printf("YES!\n");
if(x==)
printf("NO!\n");
if(x!= && x!= && x!=)
solve(x+);
}
return ;
}

最新文章

  1. MySQL 升级
  2. SharePoint 2013 数据库中手动更新用户信息
  3. 【转】Tomcat组件生命周期管理
  4. Centos6.5和Centos7 php环境搭建如何实现呢
  5. mac出现一个白条
  6. ORA-14452: 试图创建, 更改或删除正在使用的临时表中的索引
  7. Joseph cicyle&#39;s algorithm
  8. 【S13】vector和string优先于动态分配的内存
  9. 路径MTU
  10. jQuery特效手风琴特效 手写手风琴网页特效
  11. 【转】Java方向如何准备BAT技术面试答案(汇总版)
  12. 【思维】【水】 南阳oj 喷水装置(一)
  13. Java基础---String类和基本数据类型包装类
  14. C语言第五次作业函数
  15. COCOMOII的使用说明
  16. 内置函数-map
  17. orcale 使用创建日期排序然后分页每次取排序后的固定条数
  18. Quartz.NET 入门,带C#实例
  19. Linux下无法清空回收站
  20. Android -- 在xml文件中定义drawable数组

热门文章

  1. JAVA自定义监听器的示例代码
  2. 7.1——函数的定义,参数传递,return语句
  3. CSS属性操作一
  4. union关键字和字节大小端序的确定
  5. 附加数据库时,提示“Microsoft SQL Server,错误: 5120”, 解决方案
  6. 【转】AOP
  7. Atomic Builtins - Using the GNU Compiler Collection (GCC) GCC 提供的原子操作
  8. 责任链模式的具体应用 ServiceStack.Redis订阅发布服务的调用
  9. 【CODEFORCES】 C. Dreamoon and Strings
  10. WHU-1551-Pairs(莫队算法+分块实现)