Advertisement
jasonpogi1669

Check if n is a Power of 2 using popcount in C++

Oct 6th, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.20 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cin >> n;
  8.     if (__builtin_popcount(n) == 1) {
  9.         cout << "Yes";
  10.     } else {
  11.         cout << "No";
  12.     }
  13.     cout << '\n';
  14.     return 0;
  15. }
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement