Advertisement
Josif_tepe

Untitled

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