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.
< div id="description-container" class="container">
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:< br>Caution_X
date of submission:
20190930
tags:
Mathematical derivation
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. Let n be the Friend number, then n =ab+a+b=(a+1)*(b+1)-1 => n+1=(a+1)*(b+1)
2.a and b are Friend numbers, So a+1=(a'+1)*(b'+1), b+1=(a''+1)*(b''+1) until a,b=1,2
3 .Then: n+1= 2^x * 3^y
warnings:
0 requires special judgment
AC CODE:
< /pre> #include
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(< span style="color: #800000;">"YES!
"< /span>);
else printf("NO!
");
}
return 0;
}
View Code
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:< br>Caution_X
date of submission:
20190930
tags:
Mathematical derivation
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. Let n be the Friend number, then n =ab+a+b=(a+1)*(b+1)-1 => n+1=(a+1)*(b+1)
2.a and b are Friend numbers, So a+1=(a'+1)*(b'+1), b+1=(a''+1)*(b''+1) until a,b=1,2
3 .Then: n+1= 2^x * 3^y
warnings:
0 requires special judgment
AC CODE:
< /pre> #include
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(< span style="color: #800000;">"YES!
"< /span>);
else printf("NO!
");
}
return 0;
}
View Code
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:< br>Caution_X
date of submission:
20190930
tags:
Mathematical derivation
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. Let n be the Friend number, then n =ab+a+b=(a+1)*(b+1)-1 => n+1=(a+1)*(b+1)
2.a and b are Friend numbers, So a+1=(a'+1)*(b'+1), b+1=(a''+1)*(b''+1) until a,b=1,2
3 .Then: n+1= 2^x * 3^y
warnings:
0 requires special judgment
AC CODE:
< /pre> #include
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(< span style="color: #800000;">"YES!
"< /span>);
else printf("NO!
");
}
return 0;
}
View Code
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:< br>Caution_X
date of submission:
20190930
tags:
Mathematical derivation
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. Let n be the Friend number, then n =ab+a+b=(a+1)*(b+1)-1 => n+1=(a+1)*(b+1)
2.a and b are Friend numbers, So a+1=(a'+1)*(b'+1), b+1=(a''+1)*(b''+1) until a,b=1,2
3 .Then: n+1= 2^x * 3^y
warnings:
0 requires special judgment
AC CODE:
< /pre> #include
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(< span style="color: #800000;">"YES!
"< /span>);
else printf("NO!
");
}
return 0;
}
View Code
#include
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(< span style="color: #800000;">"YES!
"< /span>);
else printf("NO!
");
}
return 0;
}
View Code
#include
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(< span style="color: #800000;">"YES!
"< /span>);
else printf("NO!
");
}
return 0;
}