HDU-1719 Friend 数学推导
Posted cautx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU-1719 Friend 数学推导相关的知识,希望对你有一定的参考价值。
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.
(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 12131Sample 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==0){ printf("NO! "); continue; } n++; while(n%2==0) n/=2; while(n%3==0) n/=3; if(n==1) printf("YES! "); else printf("NO! "); } return 0; }
以上是关于HDU-1719 Friend 数学推导的主要内容,如果未能解决你的问题,请参考以下文章
支持向量机SVM原理解读,以及PyQt5融合SVM的代码实现,没有公式推导(已经很成熟,很难改公式,数学专业的可以推导学习)
BZOJ5091 摘苹果 BZOJ2017年11月月赛 数学推导 逆元