Advertisement
sherry_ahmos

H. Fair Numbers

Jul 7th, 2022
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <string>
  5. #include <queue>
  6. #include <map>
  7. #include <set>
  8. #include <string>
  9. #include <bits/stdc++.h>
  10.  
  11. using namespace std;
  12. #define ll long long
  13. #define nl endl
  14. #define cy cout << "YES\n"
  15. #define cn cout << "NO\n"
  16. #define sz s.size()
  17.  
  18. void sherry()
  19. {
  20.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  21. #ifndef ONLINE_JUDGE
  22.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  23. #endif
  24. }
  25. /*
  26. ll gcd(ll a, ll b)
  27. {
  28.     while (b)
  29.     {
  30.         a %= b;
  31.         swap(a, b);
  32.         c++;
  33.     }
  34.     return a;
  35. }
  36. ll lcm(ll a, ll b)
  37. {
  38.     return a * b / gcd(a, b);
  39. }
  40. bool is_prime(ll x)
  41. {
  42.     if (x == 2 || x == 3)
  43.         return true;
  44.     if (x == 1 || x % 2 == 0)
  45.         return false;
  46.     for (ll i = 3; i <= sqrt(x); i += 2)
  47.     {
  48.         if (x % i == 0)
  49.             return false;
  50.     }
  51.     return true;
  52. }*/
  53.  
  54. int main()
  55. {
  56.     sherry();
  57.     // freopen("sort.in", "r", stdin);
  58.     ll t;
  59.     cin >> t;
  60.     while (t--)
  61.     {
  62.         string n;
  63.         bool flag = true;
  64.         cin >> n;
  65.         ll i = 0;
  66.         while (flag)
  67.         {
  68.             string s = n;
  69.             flag = false;
  70.             for (ll i = 0; i < sz; i++)
  71.             {
  72.                 if (s[i] - '0' != 0)
  73.                 {
  74.                     if (stoll(n) % (s[i] - '0') != 0)
  75.                         flag = true;
  76.                 }
  77.             }
  78.             n = to_string(stoll(n) + 1);
  79.         }
  80.         cout << stoll(n) - 1 << nl;
  81.     }
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement