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. js使用“toFixed( )”保留小数点后两位

    例如: var a = 1.335; alert(a.toFixed(2)) // IE 1.34 //chorme 1.33 若a为字符串,则需要先转换为Number类型 如: n = Number ...

  2. linux生成多对秘钥并指定秘钥登录

    1.生成秘钥对并指定秘钥对名称: ssh-keygen -t rsa -f other -C "for other" 2.将other.pub公钥添加至要免密登录的服务器 3.使用 ...

  3. Idea-搜索快捷键

    1.Ctrl+N按名字搜索类 相当于eclipse的ctrl+shift+R,输入类名可以定位到这个类文件,就像idea在其它的搜索部分的表现一样,搜索类名也能对你所要搜索的内容多个部分进行匹配,而且 ...

  4. OpenGL光照1:颜色和基础光照

    本文是个人学习记录,学习建议看教程 https://learnopengl-cn.github.io/ 非常感谢原作者JoeyDeVries和多为中文翻译者提供的优质教程 的内容为插入注释,可以先跳过 ...

  5. 【分布式架构】--- 基于Redis组件的特性,实现一个分布式限流

    分布式---基于Redis进行接口IP限流 场景 为了防止我们的接口被人恶意访问,比如有人通过JMeter工具频繁访问我们的接口,导致接口响应变慢甚至崩溃,所以我们需要对一些特定的接口进行IP限流,即 ...

  6. wpf dual monitor

    <Window x:Class="DualMonitors.Views.WinLeft" xmlns="http://schemas.microsoft.com/w ...

  7. Typescript基础(2)——函数

    前言 今天继续typescript的学习,开始函数的学习. 函数 函数的定义 和JavaScript一样,TypeScript函数可以创建有名字的函数和匿名函数. 你可以随意选择适合应用程序的方式,不 ...

  8. LeetCode——Delete Duplicate Emails(巧用mysql临时表)

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  9. [PHP] PHP调用IMAP协议读取邮件类库

    socket.php 为连接socket的类库 imap.php 基于socket的imap协议封装 test.php 进行测试 require_once 'socket.php'; require_ ...

  10. .htaccess设置301跳转及常用技巧整理

    在虚拟主机环境中,基本上都是Apache环境.Apache的伪静态的设置,都是在网站根目录设置.htaccess文件,在.htaccess文件中无论是伪静态, 还是301跳转,甚至是防盗链和禁止某个I ...