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. pymongo和mongoengine安装和使用教程 包含常用命令行和代码示例 | pymongo and mongoengine tutorial on ubuntu 16.04

    本文首发于个人博客https://kezunlin.me/post/e88f04e5/,欢迎阅读最新内容! pymongo and mongoengine tutorial on ubuntu 16. ...

  2. JVM GC系列 — GC算法

    一.前言 从本篇文章开始,将开始一个新的系列JVM.JVM是一个非常庞大且复制的技术体系,但是对于程序猿的升级,走向更高阶所必要经历的,曾经也下决心要好好学习一番,然而毅力不足都中途放弃. GC的作用 ...

  3. 微信网站登录doem

    直接上代码 namespace CloudPrj.WeiXin {     public partial class index : System.Web.UI.Page     {         ...

  4. python处理oracle数据库的返回数据

    上代码: import SqlHelper.ORACLE as ORA import pandas as pd if __name__ == '__main__': #连接数据库 ms = ORA.O ...

  5. python基础(16):内置函数(二)

    1. lamda匿名函数 为了解决⼀些简单的需求⽽设计的⼀句话函数 # 计算n的n次⽅ def func(n): return n**n print(func(10)) f = lambda n: n ...

  6. jquery中的ajax请求到php(学生笔记)

    首先ajax的基本语法基础.(必须得引入一个jquery文件,下面的例子展示用了网上的jquery文件,要联网.) 2.请求成功(复制代码运行观察效果) <!DOCTYPE html> & ...

  7. Java生鲜电商平台-商品分类表和商品类型表的区别与数据库设计

    Java生鲜电商平台-商品分类表和商品类型表的区别与数据库设计   二者服务的对象不一样 目的也是不一样的 商品分类是为商品服务的 用来管理商品 商品类型是为扩展属性服务的 用来管理属性 举例:[转] ...

  8. scala 语法速查

    摘自官网 variables   var x = 5 Good x = 6 Variable. val x = 5 Bad x = 6 Constant. var x: Double = 5 Expl ...

  9. Java collection 集合类架构

    https://www.cnblogs.com/fireflyupup/p/4875130.html Collection List 在Collection的基础上引入了有序的概念,位置精确:允许相同 ...

  10. Netty高性能组件——FastThreadLocal源码解析(细微处见真章)

    1. 前言 netty自行封装了FastThreadLocal以替换jdk提供的ThreadLocal,结合封装的FastThreadLocalThread,在多线程环境下的变量提高了ThreadLo ...