The link for this problem WILLITST - Will it ever stop is:

http://www.spoj.com/problems/WILLITST/

The problem WILLITST - Will it ever stop is very simple. You must learn a simple trick that is :

How to know a number is power of 2:

A number 'N' is said to be power of two if and only if BITWISE AND operation of 'N' and 'N-1'

is 0.

i.e., (N&(N-1) = 0

The same thing is considered here.The thing you must take care is that the size of input number.It must be "unsigned long long" in this problem the solution for this problem WILLITST - Will it ever is given in CPP below.

#include <iostream>

using namespace std;

int main()

{

unsigned long long int n;

cin>>n;

if((n&(n-1))==0)

cout<<"TAK";

else

cout<<"NIE";

}

Happy Coding................

## No comments:

## Post a comment