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 ;
}

hdu 1719的更多相关文章

  1. HDU 1719 Friend 规律题

    解题报告:规定数字1和数字2是Friend number,然后规定,若a和b是Friend number,那么a*b+a+b也是Friend number,输入一个数,让你判断这个数是否是Friend ...

  2. HDU-1719 Friend 数学推导

    Friend HDU - 1719 Friend number are defined recursively as follows. (1) numbers 1 and 2 are friend n ...

  3. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  4. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  5. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  6. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  7. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  8. HDU图论题单

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  9. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

随机推荐

  1. BZOJ 1412: [ZJOI2009]狼和羊的故事【网络流】

    Description “狼爱上羊啊爱的疯狂,谁让他们真爱了一场:狼爱上羊啊并不荒唐,他们说有爱就有方向......” Orez听到这首歌,心想:狼和羊如此和谐,为什么不尝试羊狼合养呢?说干就干! O ...

  2. 【判连通】HDU 6113 度度熊的01世界

    http://acm.hdu.edu.cn/showproblem.php?pid=6113 [题意] 度度熊是一个喜欢计算机的孩子,在计算机的世界中,所有事物实际上都只由0和1组成. 现在给你一个n ...

  3. 【枚举】Southwestern Europe Regional Contest H - Sheldon Numbers

    https://vjudge.net/contest/174235#problem/H [题意] 求[x,y]之间有多少个Sheldon Number Sheldon Number是二进制满足以下条件 ...

  4. 内存管理(——高质量程序设计语言C/C++第16章)

    内存的分配方式: 1.静态存储区分配:全局变量,static变量等,在程序编译时已经分配了存储内存,在程序运行的整个期间一直存在 2.程序的堆栈上:程序的局部变量,包括程序的形参等,只存在于程序的运行 ...

  5. solr相关文章

    Solr集群架构概述及delta-import详细配置 背景 由于项目原因,重新熟悉了下Solr,版本为3.6,搭建了主从Solr服务,并使用DIH从RDBMS数据源增量更新索引. 其实也没什么技术含 ...

  6. $.post()用法例子

    1:删除用户操作 $('.delete').click(function(){ var classid=$(this).parent().siblings().eq(0).children().val ...

  7. dpr——设备像素比(device pixel ratio)

    设备像素比 = 物理像素 / 逻辑像素 1.物理像素 显示器上最小的物理显示单元(像素颗粒),在操作系统的调度下,每一个设备像素都有自己的颜色值和亮度值. 例如:手机大小固定,物理像素越高,画面越清晰 ...

  8. xml解析工具mashaller javaee自带解析类

    1.怎样去掉Marshaller的格式化? : JAXBContext context = JAXBContext.newInstance(Entity.class); Marshaller mars ...

  9. @Retention n. 保留

    @Retention n. 保留 学习了:https://blog.csdn.net/asdgbc/article/details/70196749 默认都是保留到class中,而在runtime中没 ...

  10. 多校训练hdu --Nice boat(线段树,都是泪)

    Nice boat Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total ...