Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. bool PotenzaDue(int);
  6.  
  7. int main() {
  8. int N, x, numdec = 0;
  9. cin >> N;
  10.  
  11. while(N != 0) {
  12. cin >> x;
  13. numdec += x * pow(2, N-1);
  14. N--;
  15. }
  16.  
  17. cout << numdec << " ";
  18.  
  19. if(PotenzaDue(numdec))
  20. cout << "SI";
  21. else
  22. cout << "NO";
  23.  
  24.  
  25.  
  26.  
  27.  
  28. return 0;
  29. }
  30.  
  31. bool PotenzaDue(int x) {
  32. for(int i = 1; i <= x; i *= 2) {
  33. if(i == x)
  34. return true;
  35. }
  36. return false;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement