Friend

HDU - 1719

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.

InputThere are several lines in input, each line has a nunnegative integer a, 0<=a<=2^30.

OutputFor 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! OJ-ID:
HDU-1719 author:
Caution_X date of submission:
20190930 tags:
数学推导 description modelling:
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. major steps to solve it:
1.设n是Friend数,则n=ab+a+b=(a+1)*(b+1)-1   =>   n+1=(a+1)*(b+1)
2.a,b都是Friend数,所以a+1=(a'+1)*(b'+1),b+1=(a''+1)*(b''+1)直到a,b=1,2
3.那么:n+1= 2^x * 3^y warnings:
0需要特判 AC CODE:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n;
while(~scanf("%lld",&n)){
if(n==){
printf("NO!\n");
continue;
}
n++;
while(n%==) n/=;
while(n%==) n/=;
if(n==) printf("YES!\n");
else printf("NO!\n");
}
return ;
}



最新文章

  1. base的应用
  2. 华为oj 字符串最后一个单词的长度
  3. java和c#使用hessian通信
  4. HDU 4951 Multiplication table(2014 Multi-University Training Contest 8)
  5. 浅谈对ionic项目的理解
  6. UE4 中在 Actor 中动态 Create Component 与ChildActor 的 小笔记
  7. 变形--旋转 rotate()
  8. C语言 类型
  9. Python包管理工具介绍
  10. cisco LAN
  11. Unity3D ShaderLab 布料着色器
  12. Jackson学习笔记-对象序列化
  13. Zend Framework 2参考Zend\Authentication(数据库表认证)
  14. BZOJ 1627: [Usaco2007 Dec]穿越泥地( BFS )
  15. ZooKeeper的安装、配置、启动和使用(一)——单机模式
  16. 记Javascript的编写方式的全新学习
  17. 动态添加数据源,根据用户登录切换数据库.编程式Spring事务.
  18. TypeError: $(…).tooltip is not a function
  19. 函数 y=x^x的分析
  20. MP3文件结构解析(超详细)

热门文章

  1. tomcat9上传文件失败错误
  2. nginx: [emerg] unknown directive “ ” in /usr/local/nginx/nginx.conf.conf:xx报错处理
  3. Core源码(五)IQueryable(转)
  4. asp.net 关于gridview使用的一些小技巧
  5. C# 判断(Excel)文件是否已经打开
  6. Linux问题记录——主机名变成了bogon
  7. 自定义Vue组件打包、发布到npm以及使用
  8. postgres 导出单个表的语句
  9. SQL学习_WHERE 数据过滤
  10. 重温《NoSQL精粹》