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
  1. 3
  2. 13121
  3. 12131
 
Sample Output
  1. YES!
  2. YES!
  3. NO!
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  1905 2082 1073 1715 1257

  1. /*刚刚看到这道题的时候一心只想着打表,但是试了几次都超时,没想到有这种规律....
  2. c=ab+b+a=b(a+1)+b=(b+1)(a+1)-1,c+1=(b+1)(a+1),所以输入的数加一之后,它只要是2或者3的倍数就可以*/
  3. #include<stdio.h>
  4. #include<string.h>
  5. int main()
  6. {
  7. int n;
  8. while(scanf("%d",&n)!=EOF)
  9. {
  10. if(n<1)
  11. {
  12. printf("NO!\n");
  13. }
  14. else
  15. {
  16. n=n+1;
  17. while(n%2==0)
  18. n=n/2;
  19. while(n%3==0)
  20. n=n/3;
  21. if(n==1)
  22. printf("YES!\n");
  23. else printf("NO!\n");
  24. }
  25. }
  26. }

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. Ajax 传递json字符串到客户端时报 Internal server error

    架构:struts2+JQuery 需求:就是前台请求后台,后台查询数据库,将数据转换成json格式,使用struts2框架赋值给action内的变量jsonStr,前台通过 response.jso ...

  2. JQuery 兼容所有浏览器的复制到剪切板功能

    灵机一动想的点子,应该不难理解 <textarea onmousedown='selectAll(this);'>11111</textarea> function selec ...

  3. 精确获取对象的类型:Object.prototype.toString()

    https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/toString

  4. Android 概览屏幕

    文章照搬过来的:原文地址https://developer.android.google.cn/guide/components/recents.html 概览屏幕(也称为最新动态屏幕.最近任务列表或 ...

  5. ajax-工作原理,包含技术,缺陷

    1:原理 2:包含技术 3:缺陷

  6. google浏览器 打印A4 最大宽度和高度px

    width: 1563px;(max) + = 分页了 + = 分页了 + = 没有分页 / ViewBag.results[].Count)); <td width="15%&quo ...

  7. Golang实现常用排序算法

    主函数package main import ( "fmt" "math/rand" "sort" "time") co ...

  8. Spring Cloud Alibaba、Spring Boot、Spring Cloud对应版本关系

    Spring Boot Spring Cloud Spring Cloud Alibaba 2.1.x Greenwich 0.9.x 2.0.x Finchley 0.2.x 1.5.x Edgwa ...

  9. eas之单据转换规则

    /**  * BOTP单据转换  * @param botpNum 转换规则编号  * @param BillInfo 原单据  */ public static void BOTP(String b ...

  10. PIPE、SIGNAL(day11)

    一.管道 管道分为两种: 无名管道 有名管道 无名管道用于具有亲缘关系的进程间通讯.无名管道是单工的. 有内核管理的一块内存空间. 使用管道,系统提供了pipe() #include <unis ...