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. Contest Hunter #46 T1 磁力块 [花式暴力]

    将所有石头按距离远近排序,将所有取到的时候扔进堆里维护最大磁力强度. 贪心,每次用强度最强的磁石尝试吸引地上的石头,扫完区间以后,这块石头就再也不会用到了. 在此基础上可以做些小优化,比如说优化未取石 ...

  2. Android服务Service

    安卓Service服务 一    Service简介 Service是运行在后台的,没有界面的,用来处理耗时比较长的.Service不是一个单独的进程,也不是一个单独的线程. Service有两种类型 ...

  3. Pytho操作MySQL

    一.相关代码 数据库配置类 MysqlDBConn.py 01 #encoding=utf-8 02 ''' 03 Created on 2012-11-12 04    05 @author: St ...

  4. php 压缩数据存储

    php 压缩数据存储 当接收到大量的数据时,存储到数据库和从数据库读取时,时间都比较慢,所以压缩一下入库可能会好一点. 仅供参考!!! 封装的压缩数据函数: /** * 压缩数据 * @param s ...

  5. CodeForces 599C Day at the Beach

    预处理一下i到n的最小值. #include<cstdio> #include<cstring> #include<cmath> #include<algor ...

  6. POJ 1511 【heap+dij】

    题意: t组样例. 每组有n个节点,有m条单向边. 有m组输入,每组a b c 表示从a到b的单向边的权值是c. 求解,从编号为1的节点出发,有n-1个人,要求他们分别到达编号从2到n的节点再返回,所 ...

  7. 51nod 1499 (最小割)

    题意 分析 将一些点分成两个集合,很明显的最小割问题 设一个S.T,和S相连的点表示在B集合中,和T相连的点表示在A集合中 因为原题是完美值最大,我们转换一下,变成损失的价值最小,那么就是最小割问题了 ...

  8. Spring的AOP AspectJ切入点语法详解(转)

    一.Spring AOP支持的AspectJ切入点指示符 切入点指示符用来指示切入点表达式目的,在Spring AOP中目前只有执行方法这一个连接点,Spring AOP支持的AspectJ切入点指示 ...

  9. java大文件的分割和合并

    原文:http://www.open-open.com/code/view/1441679313430 import java.io.File; import java.io.FileInputStr ...

  10. &quot;undefined reference to strptime&quot;之自己定义strptime函数

    简单介绍   strptime()函数可以依照特定时间格式将字符串转换为时间类型.简单点说可以将字符串时间转化为时间戳. 这个函数包括在time.h头文件里,在Unix或者类Unix系统中,我们会常常 ...