Advertisement
fahad005

1542B.cpp

Jul 12th, 2021
1,009
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. //
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define mx 100010
  7. #define mod 1000000007
  8. #define inf INT_MAX
  9. #define pi acos(-1)
  10. #define endl '\n'
  11. #define pb push_back
  12. #define pll pair<ll, ll>
  13. #define Fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
  14. //
  15. int main() {
  16.     ll t;
  17.     cin >> t;
  18.  
  19.     while (t--) {
  20.         ull n, a, b;
  21.         cin >> n >> a >> b;
  22.  
  23.         if (a == 1 && b != 1) {
  24.             if (n % b == 1) cout << "Yes" << endl;
  25.             else cout << "No" << endl;
  26.             continue;
  27.         }
  28.         else if (b == 1) {
  29.             cout << "Yes" << endl;
  30.             continue;
  31.         }
  32.  
  33.         ull j = 0;
  34.         while (1) {
  35.             ull x = pow(a, j++);
  36.             if (x > n) {
  37.                 cout << "No" << endl;
  38.                 break;
  39.             }
  40.             if ((n - x) % b == 0) {
  41.                 cout << "Yes" << endl;
  42.                 break;
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement