Advertisement
Guest User

E_ACM

a guest
Apr 26th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int step3[10] = {1, 3, 9, 27, 81, 243, 729, 2187, 6561};
  7.  
  8. int main()
  9. {
  10.     int n;
  11.     cin >> n;
  12.     bool flag = false;
  13.  
  14.     for (int i = 8; i >= 0; i--)
  15.     {
  16.         if (n >= step3[i]) n = n - step3[i];
  17.         //if (n == 0) flag = true;
  18.     }
  19.  
  20.     if (n == 0) flag = true;
  21.  
  22.     if (flag) cout << "YES\n";
  23.     else cout << "NO\n";
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement