Header Ads Widget

Conject-It !

 Problem:-

You are given a number N. You can perform the following operations on N any number of times:

> If N is evendivide N by 2.

> If N is odd, replace N with 3N+1.

 

Your task is to find out, for a given Nif it is possible to reach the number 1 after performing the above two valid operations on N any number of times.

 

INPUT:

  • First-line contains T denoting the number of test cases.
  • Next T lines contain just one integer, N.

 

OUTPUT:

Print "YES" (without the quotes) if it is possible to reach 1 for the given N. Else print "NO"(without quotes).

 

Constraints:

1<= T <=100

2<= N <= 10100,000

       

Sample Input
1
21
Sample Output
YES
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The steps are:

21 --> 64 --> 32 --> 16 --> 8 --> 4 --> 2 --> 1.

Code:-

 Here if we take any even number and start dividing by 2 then at last we will get 1 for all number . similarly if we take a odd then we have to change it in (3*n+1) according to question and after this process it become a even number and when we start dividing it by 2 then we will get 1.

So we have to  print "YES" in all cases.

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t,i;
  long long int n;
  cin>>t;
  while(t--)
  {
    cin>>n;
    cout<<"YES"<<endl;

  }
return 0;
}



Post a Comment

0 Comments