Cod sursa(job #3169659)

Utilizator RobertAcAcatrinei Robert-Marian RobertAc Data 15 noiembrie 2023 18:58:13
Problema GFact Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <bits/stdc++.h>
#ifdef LOCAL
#define in cin
#define out cout
#endif
#define int int64_t
using namespace std;

#ifndef LOCAL
ifstream in("gfact.in");
ofstream out("gfact.out");
#endif

int countt(int maxx,int base)
{
    int cnt=0;
    int base1=base;
    while(base1<=maxx)
    {
        cnt+=maxx/base1;
        base1*=base;
    }
    return cnt;
}


signed main()
{
    int p,q;in>>p>>q;
    int st = 1, dr = 1e16;
    while (st<dr)
    {
        int mid=(st+dr)/2;
        //cerr<<st<<' '<<dr<<'\n';
        //cerr<<mid<<' '<<p<<' '<<countt(mid,p)<<'\n';
        if(countt(mid,p)>=q)
        {
            dr=mid;
        }
        else
        {
            st=mid+1;
        }
    }
    out<<st;
}