-
Notifications
You must be signed in to change notification settings - Fork 0
/
powerOf2.cpp
47 lines (35 loc) · 926 Bytes
/
powerOf2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// { Driver Code Starts
//Initial Template for C++
#include<bits/stdc++.h>
using namespace std;
// } Driver Code Ends
//User function Template for C++
class Solution{
public:
// Function to check if given number n is a power of two.
bool isPowerofTwo(long long n){
// Your code here
if(n==0) return false;
if(ceil(log2(n))==floor(log2(n))) return true;
return false;
}
};
// { Driver Code Starts.
// Driver code
int main()
{
int t;
cin>>t;//testcases
for(int i=0;i<t;i++)
{
long long n; //input a number n
cin>>n;
Solution ob;
if(ob.isPowerofTwo(n))//Now, if log2 produces an integer not decimal then we are sure raising 2 to this value
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
// } Driver Code Ends