Hust oj 2118 Friend number(递推)
来源:互联网 发布:git mac客户端 编辑:程序博客网 时间:2024/04/30 17:04
Friend numberTime Limit: 1000 MSMemory Limit: 32768 KTotal Submit: 91(55 users)Total Accepted: 63(53 users)Rating: Special Judge: NoDescription
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.
There are multiple test cases.
For each test case:
Line 1: A nonnegative integer a, 0<=a<=2^30.
For each test case, output one line, if a is a friend number, output "YES!", otherwise output "NO!".
Sample Input31312112131Sample Output
YES!YES!NO!
设Friendnumber = a+b+ab+1-1,变形为(a+1)(b+1)-1,然后再用(c+1)(d+1)-1代替其中的a,以此类推,直到最后推到a=1,b=2,代入得2^x + 3^y - 1.
#include<cstdio>#include<iostream>#include<cstring>#include<cmath>using namespace std;int main(){ int n; while(~scanf("%d",&n)) { int flag = 0; if(!n) { printf("NO!\n"); continue; } for(int i=0;i<=30;i++) { for(int j=0;j<=30;j++) { if(int(pow(2,i)) * int(pow(3,j)) - 1 == n) { printf("YES!\n"); flag = 1; break; } } if(flag) break; } if(!flag) printf("NO!\n"); }}
0 0
- Hust oj 2118 Friend number(递推)
- hdu 1719 / 哈理工 oj 2118 Friend number【递推+思维】
- Hust oj 1074 Hexagonal Tiles(递推)
- Hust oj 1124 Final Destination(递推)
- Hust oj 1986 大悲咒(递推)
- Hust oj 1929 走三方,路迢迢水长长(递推)
- Hust oj 2084(大数)
- 杭电OJ(HDOJ)1005题:Number Sequence(规律递推)
- hdu6198 number number number(递推公式黑科技)
- Hust oj 2038 联系网络(MST)
- Hust oj 2234 土豪银行(贪心)
- Hust oj 1143 泉水(dfs)
- Hust oj 2113 Count(Map)
- Hust oj 1305 多边形(数学)
- Hust oj 1677 一个函数(栈)
- Hust oj 1039 修路(二分)
- Hust oj 1369 Buy Computers(水题)
- Hust oj 2121 你猜猜(水题)
- 百度UEditor编辑器ueditor.setContent总是报错
- javaee
- Container With Most Water
- 微信公众号01: ase实现access_token的存储和被动刷新
- node.js实现简单的网络爬虫程序
- Hust oj 2118 Friend number(递推)
- ueditor1_4_3-utf8-jsp 配置实现上传图片的功能遇到的问题,改变图片上传请求地址
- Hibernata的特点
- jdk安装
- todo 基本设计模式
- jQuery 从零开始学习 (六) 工具函数
- Ueditor编辑保存的内容网页显示时背景等信息无效果---参考UEditor官方文档之编辑内容展示
- linux中守护进程启停工具start-stop-daemon使用介绍
- Android studio模拟器 Intel HAXM Intel virtualization technology(VT-x) is not turned on 解决办法