fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. unsigned long long int n;
  7. cin>>n;
  8. int one=0;
  9.  
  10. while(n > 0) {
  11. if(n%2==1)
  12. ++one;
  13. n=n/2;
  14. }
  15.  
  16. if(one==1)
  17. cout<<" number is power of 2"<<endl;
  18. else cout<<" number is not power of 2"<<endl;
  19.  
  20. return 0;
  21. }
Success #stdin #stdout 0s 2732KB
stdin
16
stdout
 number is power of 2