--- determine whether there is a recursive element

Topic Link
garlic king had a collection of MM is generated:

(1) is a collection of known kk MM element;
(2) if the MM yy is the element, then, 2y + 12y + 1 and 3y + 13y + 1 is an element MM;
(3) In addition to the above two cases no other number can be an element of MM.
Question: Given kk and xx (0 \ Le k \ the X-Le \ Le 50≤k≤x≤10 10 ^
5
), is xx MM please determine whether the elements.

If so, output "YES", otherwise output "NO".

Input format
input and an integer kk xx, separated by commas.

Output format
If so, output "YES", otherwise output "NO".

Extra spaces at the end of each row, the answer does not affect the validity of the output

Sample Input
0,22
Sample Output
YES

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <cstring>
using namespace std;
int k,x;
bool judge(int n)
{
    if(n>x)
        return false;
    if(n==x)
        return true;
    if(judge(2*n+1)||judge(3*n+1))
        return true;
    return false;
}
int main()
{
    char c;
    cin>>k>>c>>x;
    int n=k;
    bool f=judge(n);
    if(f==true)
       cout<<"YES"<<endl;
    else
       cout<<"NO"<<endl;
}

Published 67 original articles · won praise 2 · Views 1805

Guess you like

Origin blog.csdn.net/weixin_44641254/article/details/104226134