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 ;
}



HDU-1719 Friend 数学推导的更多相关文章

  1. hdu.5211.Mutiple(数学推导 && 在logn的时间内求一个数的所有因子)

    Mutiple  Accepts: 476  Submissions: 1025  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 6553 ...

  2. HDU 5734 Acperience(数学推导)

    Problem Description Deep neural networks (DNN) have shown significant improvements in several applic ...

  3. HDU 5984 题解 数学推导 期望

    Let’s talking about something of eating a pocky. Here is a Decorer Pocky, with colorful decorative s ...

  4. HDU 5073 Galaxy(Anshan 2014)(数学推导,贪婪)

    Galaxy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total S ...

  5. 借One-Class-SVM回顾SMO在SVM中的数学推导--记录毕业论文5

    上篇记录了一些决策树算法,这篇是借OC-SVM填回SMO在SVM中的数学推导这个坑. 参考文献: http://research.microsoft.com/pubs/69644/tr-98-14.p ...

  6. 关于不同进制数之间转换的数学推导【Written By KillerLegend】

    关于不同进制数之间转换的数学推导 涉及范围:正整数范围内二进制(Binary),八进制(Octonary),十进制(Decimal),十六进制(hexadecimal)之间的转换 数的进制有多种,比如 ...

  7. UVA - 10014 - Simple calculations (经典的数学推导题!!)

    UVA - 10014 Simple calculations Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...

  8. 『sumdiv 数学推导 分治』

    sumdiv(POJ 1845) Description 给定两个自然数A和B,S为A^B的所有正整数约数和,编程输出S mod 9901的结果. Input Format 只有一行,两个用空格隔开的 ...

  9. LDA-线性判别分析(二)Two-classes 情形的数学推导

    本来是要调研 Latent Dirichlet Allocation 的那个 LDA 的, 没想到查到很多关于 Linear Discriminant Analysis 这个 LDA 的资料.初步看了 ...

随机推荐

  1. C++入门到理解阶段二基础篇(1)——简介与环境安装

    1.C++ 简介 C++ 是一种静态类型的.编译式的.通用的.大小写敏感的.不规则的编程语言,支持过程化编程.面向对象编程和泛型编程. C++ 被认为是一种中级语言,它综合了高级语言和低级语言的特点. ...

  2. keras使用多GPU并行训练模型 | keras multi gpu training

    本文首发于个人博客https://kezunlin.me/post/95370db7/,欢迎阅读最新内容! keras multi gpu training Guide multi_gpu_model ...

  3. httpclient超时时间设置及代理设置

    超时时间 设置HttpClient的超时时间,非常有必要性,因为httpclient 默认超时时间很长,自己可以测试一下是多久,设置超时时间否则会影响自己系统的业务逻辑,例如阻塞系统,影响系统的吞吐量 ...

  4. CENTOS 7 内网网段在用IP地址检测Shell脚本优化版

    脚本内容 #!/bin/bash ############################################################################# # 用途: ...

  5. 使用ADO.NET实体数据模型

    前景:要操作的数据表必须添加主键(方式:进入数据库-->数据表名-->设计-->列名右键-->设置主键) 可在服务器资源管理器中查看是否设置了主键(主键会有一把钥匙的图样) 1 ...

  6. SmobilerService 开发者日志(一):什么是 SmobilerService ,它为开发者带来了什么价值?

    初见 SmobilerService 你会发现几个版本,以及一些价格. 所以,"Smobiler 是要收费了吗?" 这是开发团队在幕后悄悄观察 Service 推广开始后,用户向运 ...

  7. 安装新版Magisk卡在启动页面等问题以及解决办法

      手持小米9,之前更新了新版本的Magisk Manager之后,发现手机再打开会一直卡在进入界面无法启动(如下图显示)   逛了逛Github.XDA.Stack Overflow等论坛,大致结论 ...

  8. 修复\okldr.mbr ,状态0x000000f

    问题: 系统出错显示: 修复\okldr.mbr ,状态0x000000f. 方法: 利用bcdeidt删除错误启动项. bcdeidt的应用 1.启动系统,点击开始,运行中输入cmd,鼠标右键管理员 ...

  9. MySQL事务。

    相关资料:https://zhuanlan.zhihu.com/p/70701037        https://zhuanlan.zhihu.com/p/59061106 一.事务. 1.概念.事 ...

  10. 七、数据提取之JSON与JsonPATH

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,它使得人们很容易的进行阅读和编写.同时也方便了机器进行解析和生成.适用于进行数据交互的场景,比如网站前台与 ...