Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- //#define int long long
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef long double ld;
- typedef string str;
- typedef vector <int> vi;
- typedef pair <int, int> pii;
- int q;
- ull n;
- ull three[39];
- ull sum;
- void build()
- {
- ll p = 1;
- for (int i = 0; i < 39; ++i) {
- three[i] = p;
- sum += p;
- p *= 3;
- }
- }
- void read()
- {
- cin >> n;
- }
- void solve()
- {
- ull t = sum;
- for (int i = 38; i >= 0; --i) {
- if (t - three[i] >= n) t -= three[i];
- }
- cout << t << "\n";
- }
- signed main()
- {
- ios::sync_with_stdio(0);cin.tie(nullptr);
- build();
- cin >> q;
- for (int i = 0; i < q; ++i) {
- read();
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement