Advertisement
Josif_tepe

Untitled

Mar 30th, 2025
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. #include <map>
  5. using namespace std;
  6. typedef long long ll;
  7.  
  8. int main() {
  9.     ios_base::sync_with_stdio(false);
  10.     ll k, x;
  11.     cin >> k >> x;
  12.    
  13.     ll res = 1e18;
  14.     if(x % k == 0) {
  15.         res = x / k;
  16.     }
  17.    
  18.     ll power = 1;
  19.     for(int i = 0; i < 100; i++) {
  20.         ll tmp = power * k;
  21.        
  22.         if(tmp <= x) {
  23.             if(x % tmp == 0) {
  24.                 ll n = x / tmp;
  25.                 if(n * power * k == x) {
  26.                     res = min(res, n + i);
  27.                 }
  28.             }
  29.         }
  30.         else {
  31.             break;
  32.         }
  33.         power *= k;
  34.     }
  35.    
  36.     if(res == 1e18) {
  37.         res = -1;
  38.     }
  39.     cout << res << endl;
  40.    
  41.    
  42.     return 0;
  43.    
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement