Friend

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2207    Accepted Submission(s): 1108

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

/*刚刚看到这道题的时候一心只想着打表,但是试了几次都超时,没想到有这种规律....
c=ab+b+a=b(a+1)+b=(b+1)(a+1)-1,c+1=(b+1)(a+1),所以输入的数加一之后,它只要是2或者3的倍数就可以*/
#include<stdio.h>
#include<string.h>
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
if(n<1)
{
printf("NO!\n");
}
else
{
n=n+1;
while(n%2==0)
n=n/2;
while(n%3==0)
n=n/3;
if(n==1)
printf("YES!\n");
else printf("NO!\n");
}
}
}

friend(hdoj 1719)的更多相关文章

  1. 最小生成树(HDOJ 1863)

    畅通工程 http://acm.hdu.edu.cn/showproblem.php?pid=1863 1.Prim算法: Prim算法是由一个点(最初的集合)向外延伸,找到与集合相连权值最小的边, ...

  2. 射击比赛 (POJ 1719) 题解

    [问题描述] 我们假设射击的目标是一个由R*C(2≤R≤C≤ 1000)个小方格组成的矩形网格.网格中每一列恰有2个白色的小方格和R-2个黑色的小方格.定义网格的行从顶至底编号为1~R,列从左至右编号 ...

  3. 并查集(HDOJ 1856)

    并查集   英文:Disjoint Set,即“不相交集合” 将编号分别为1…N的N个对象划分为不相交集合, 在每个集合中,选择其中某个元素代表所在集合. 常见两种操作: n       合并两个集合 ...

  4. Elevator(hdoj 1008)

    Problem Description The highest building in our city has only one elevator. A request list is made u ...

  5. 【HDOJ 2255】奔小康赚大钱(KM算法)

    [HDOJ 2255]奔小康赚大钱(KM算法) 奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  6. HDOJ 1716 排列2(next_permutation函数)

    Problem Description Ray又对数字的列产生了兴趣: 现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数. Input 每组数据占一行,代表四张卡 ...

  7. HDOJ 1028 Ignatius and the Princess III(递推)

    Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...

  8. HDOJ 1014 Uniform Generator(公约数问题)

    Problem Description Computer simulations often require random numbers. One way to generate pseudo-ra ...

  9. HDOJ 1166 敌兵布阵 (线段树)

    题目: Problem Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Ti ...

随机推荐

  1. Ionic3 环境搭建以及基础配置实现(更新中)

    GitHub:https://github.com/Teloi 环境配置输入以下命令安装 Ionic (如果刚才设置了淘宝镜像源,可以使用 cnpm 代替 npm):npm install -g io ...

  2. wamp中的mysql服务与原来安装的mysql服务冲突的解决办法

    如果原来机器上已经安装了mysql,在安装wamp之后,打开wamp上的mysql时会打不开,或者会将原来安装的mysql服务关闭.原因是两个mysql共用了3306端口,解决办法是更改其中的一个端口 ...

  3. 使用curl 上传文件,multipart/form-data

    使用curl 上传文件,multipart/form-data 1. 不使用-F,curl内置multipart/form-data功能: 2. 文件内容与真实数据无关,用abc代替数据,依然可以上传 ...

  4. DHCP 和 MDT 分开服务器的设置方法

    DHCP设置 043:供应商特定信息:01 04 00 00 00 00 FF 060:PXEClient:PXEClient 066:启动服务器主机名:IP 067:启动文件名:\Boot\x86\ ...

  5. 如何在编辑器打开Java程序

    我们都知道运行JAVA文件,可以从软件控制台运行我们写好的java文件,也可以从windows窗口运行,我们最开始接触的是通过windows窗口来运行java文件,下面简单介绍一下如何如何在编辑器打开 ...

  6. http 请求头示例

      POST /3-0/app/account/item HTTP/1.1 Host 10.100.138.32:8046 Content-Type application/json Accept-E ...

  7. nginx_安装测试

    首先安装环境: [root@local nginx-1.9.14]#  yum install gcc-c++  pcre pcre-devel  zlib zlib-devel openssl op ...

  8. 上传菜品数据&生成点餐二维码

    基础数据上传 在门店助手打开数据上传功能,点击上传到微餐厅3.0,,即将门店本地的基础数据上传到线上. 注意1:上传前,需要在线下系统维护好基础数据 注意2:线下基础数据发生更改时,需要手动在门店助手 ...

  9. HDU 2266 How Many Equations Can You Find(模拟,深搜)

    题目 这是传说中的深搜吗....不确定,,,,貌似更加像是模拟,,,, //我要做深搜题目拉 //实际上还是模拟 #include<iostream> #include<string ...

  10. top问题

    1. 从10万个数中找10个最大的数 对于这种题目,最普通的想法是先对这10万个数进行排序,然后再选取数组中前10个数,即为最后的答案,排序算法的时间复杂度不下于O(N lgN).最好的方法是建立一个 ...