Skip to content

Commit 7c053ac

Browse files
Merge pull request #504 from codeX1616/codeX1616/OptimizedExponentCheck
codeX1616-Optimized approach to check if a number is an exponent of two
2 parents 4f795ea + 874108c commit 7c053ac

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

CPP/OptimizedExponentOfTwoCheck.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
bool isAnExponentOfTwo(int n) {
5+
return ((n & (n-1)) == 0);
6+
}
7+
8+
int main() {
9+
int n;
10+
cin >> n;
11+
cout << (isAnExponentOfTwo(n) ? "YES" : "NO") << endl;
12+
return 0;
13+
}

0 commit comments

Comments
 (0)