SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 175 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. //#define int long long
  3. using namespace std;
  4.  
  5.  
  6. typedef long long ll;
  7. typedef unsigned long long ull;
  8. typedef long double ld;
  9. typedef string str;
  10. typedef vector <int> vi;
  11. typedef pair <int, int> pii;
  12.  
  13. int q;
  14. ull n;
  15. ull three[39];
  16. ull sum;
  17.  
  18. void build()
  19. {
  20.     ll p = 1;
  21.     for (int i = 0; i < 39; ++i) {
  22.         three[i] = p;
  23.         sum += p;
  24.         p *= 3;
  25.     }
  26. }
  27.  
  28. void read()
  29. {
  30.     cin >> n;
  31. }
  32.  
  33. void solve()
  34. {
  35.     ull t = sum;
  36.     for (int i = 38; i >= 0; --i) {
  37.         if (t - three[i] >= n) t -= three[i];
  38.     }
  39.     cout << t << "\n";
  40. }
  41.  
  42. signed main()
  43. {
  44.     ios::sync_with_stdio(0);cin.tie(nullptr);
  45.     build();
  46.     cin >> q;
  47.     for (int i = 0; i < q; ++i) {
  48.         read();
  49.         solve();
  50.     }
  51.     return 0;
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top