Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <set>
  6. #include <cmath>
  7. #include <stack>
  8. #include <map>
  9. #define int unsigned long long
  10. #define double long double
  11. using namespace std;
  12.  
  13. int f(int n) {
  14. int st2 = 1;
  15. int st3 = 1;
  16. int res = 0;
  17. while (n > 0) {
  18. if (n % 2 == 1)
  19. res += st3;
  20. n /= 2;
  21. st3 *= 3;
  22. }
  23. return res;
  24. }
  25.  
  26. signed main() {
  27. int t;
  28. cin >> t;
  29. vector<int> st3;
  30. int st = 1;
  31. while (st <= 1000000000000000000)
  32. st3.push_back(st), st *= 3;
  33. for (int ii = 0; ii < t; ii++) {
  34. int n;
  35. cin >> n;
  36. int a = 0;
  37. int b = 10000;
  38. while (a + 1 < b) {
  39. int c = (a + b) / 2;
  40. if (f(c) < n)
  41. a = c;
  42. else
  43. b = c;
  44. }
  45. cout << f(b) << endl;
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement