Beingamanforever

Conversion to the base 9 To remove all 4s

Dec 25th, 2024
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. /**
  2.  *    author:  compounding
  3.  *    created: 2024-12-25 17:06:22
  4.  **/
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
  8. #define NeedForSpeed                  \
  9.     ios_base::sync_with_stdio(false); \
  10.     cin.tie(NULL);                    \
  11.     cout.tie(NULL);
  12. #define int long long
  13. #define all(x) (x).begin(), (x).end()
  14. typedef vector<int> vi;
  15. typedef vector<bool> vb;
  16. typedef vector<vi> vvi;
  17. typedef vector<pair<int, int>> vpi;
  18. #define f first
  19. #define s second
  20. #define yes cout << "YES" << endl
  21. #define no cout << "NO" << endl
  22. #define endl "\n"
  23. const int mod = 1000000007;
  24. int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
  25. int convertbase(int k, int base)
  26. {
  27.     string s = "";
  28.     while (k > 0)
  29.     {
  30.         int digit = k % base;
  31.         if (digit <= 3)
  32.         {
  33.             s += to_string(digit);
  34.         }
  35.         else
  36.         {
  37.             s += to_string(digit + 1);
  38.         }
  39.         k /= base;
  40.     }
  41.     reverse(all(s));
  42.     return stoll(s);
  43. }
  44. void solve()
  45. {
  46.     // we dont want 4 so we convert k in the base 9
  47.     int k;
  48.     cin >> k;
  49.     int ans = convertbase(k, 9);
  50.     cout << ans << endl;
  51.     return;
  52. }
  53.  
  54. signed main()
  55. {
  56.     NeedForSpeed;
  57.     int t = 1;
  58.     cin >> t;
  59.     while (t--)
  60.     {
  61.         solve();
  62.     }
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment