hdu 1719
2024-09-05 07:53:47
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
心塞的一题。。。。。。。
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 ;
}
最新文章
- MySQL 升级
- SharePoint 2013 数据库中手动更新用户信息
- 【转】Tomcat组件生命周期管理
- Centos6.5和Centos7 php环境搭建如何实现呢
- mac出现一个白条
- ORA-14452: 试图创建, 更改或删除正在使用的临时表中的索引
- Joseph cicyle&#39;s algorithm
- 【S13】vector和string优先于动态分配的内存
- 路径MTU
- jQuery特效手风琴特效 手写手风琴网页特效
- 【转】Java方向如何准备BAT技术面试答案(汇总版)
- 【思维】【水】 南阳oj 喷水装置(一)
- Java基础---String类和基本数据类型包装类
- C语言第五次作业函数
- COCOMOII的使用说明
- 内置函数-map
- orcale 使用创建日期排序然后分页每次取排序后的固定条数
- Quartz.NET 入门,带C#实例
- Linux下无法清空回收站
- Android -- 在xml文件中定义drawable数组
热门文章
- JAVA自定义监听器的示例代码
- 7.1——函数的定义,参数传递,return语句
- CSS属性操作一
- union关键字和字节大小端序的确定
- 附加数据库时,提示“Microsoft SQL Server,错误: 5120”, 解决方案
- 【转】AOP
- Atomic Builtins - Using the GNU Compiler Collection (GCC) GCC 提供的原子操作
- 责任链模式的具体应用 ServiceStack.Redis订阅发布服务的调用
- 【CODEFORCES】 C. Dreamoon and Strings
- WHU-1551-Pairs(莫队算法+分块实现)