Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <cmath>
- #include <stack>
- #include <map>
- #define int unsigned long long
- #define double long double
- using namespace std;
- int f(int n) {
- int st2 = 1;
- int st3 = 1;
- int res = 0;
- while (n > 0) {
- if (n % 2 == 1)
- res += st3;
- n /= 2;
- st3 *= 3;
- }
- return res;
- }
- signed main() {
- int t;
- cin >> t;
- vector<int> st3;
- int st = 1;
- while (st <= 1000000000000000000)
- st3.push_back(st), st *= 3;
- for (int ii = 0; ii < t; ii++) {
- int n;
- cin >> n;
- int a = 0;
- int b = 10000;
- while (a + 1 < b) {
- int c = (a + b) / 2;
- if (f(c) < n)
- a = c;
- else
- b = c;
- }
- cout << f(b) << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement