Cod sursa(job #2796870)

Utilizator LeonGSLeo Jechiu LeonGS Data 8 noiembrie 2021 21:56:25
Problema GFact Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <bits/stdc++.h>
using namespace std;
long long p;
int q;

long long howMany(long long x) {
   long long putere=p;
   long long cnt=0;
   while(putere<=x){
    cnt+=x/putere;
    putere*=p;
   }
   return cnt;
}


int main(){
ifstream cin("gfact.in");
ofstream cout("gfact.out");
cin >> p >> q;
long long left=1,right=60000000000000,sol=0;
while(left<=right){
    long long mid=(left+right)/2;
    if(howMany(mid)>=q){
        sol=mid;
        right=mid-1;
    }
    else{
        left=mid+1;
    }
}
cout << sol;


return 0;
}