HDU-1719 Friend 数学推导
2024-08-30 08:12:25
Friend
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.
(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
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 ;
}
最新文章
- base的应用
- 华为oj 字符串最后一个单词的长度
- java和c#使用hessian通信
- HDU 4951 Multiplication table(2014 Multi-University Training Contest 8)
- 浅谈对ionic项目的理解
- UE4 中在 Actor 中动态 Create Component 与ChildActor 的 小笔记
- 变形--旋转 rotate()
- C语言 类型
- Python包管理工具介绍
- cisco LAN
- Unity3D ShaderLab 布料着色器
- Jackson学习笔记-对象序列化
- Zend Framework 2参考Zend\Authentication(数据库表认证)
- BZOJ 1627: [Usaco2007 Dec]穿越泥地( BFS )
- ZooKeeper的安装、配置、启动和使用(一)——单机模式
- 记Javascript的编写方式的全新学习
- 动态添加数据源,根据用户登录切换数据库.编程式Spring事务.
- TypeError: $(…).tooltip is not a function
- 函数 y=x^x的分析
- MP3文件结构解析(超详细)
热门文章
- tomcat9上传文件失败错误
- nginx: [emerg] unknown directive “ ” in /usr/local/nginx/nginx.conf.conf:xx报错处理
- Core源码(五)IQueryable(转)
- asp.net 关于gridview使用的一些小技巧
- C# 判断(Excel)文件是否已经打开
- Linux问题记录——主机名变成了bogon
- 自定义Vue组件打包、发布到npm以及使用
- postgres 导出单个表的语句
- SQL学习_WHERE 数据过滤
- 重温《NoSQL精粹》