Cod sursa(job #3209037)

Utilizator andreiciocanCiocan Andrei andreiciocan Data 1 martie 2024 19:00:24
Problema GFact Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("gfact.in");
ofstream fout("gfact.out");
int main()
{
    long long p,q,b;
    long long st,dt;
    fin>>p>>q;
    st=p;
    dt=p*q;
    while(st<=dt)
    {
        int m=(st+dt)/p/2;
        m=m*p;
        long long s=0;
        for(long long i=p;i<=m;i*=p)
        {
            s=s+m/i;
        }
        if(s>=q)
        {
            dt=m-p;
            b=m;
        }
        else
        {
            st=m+p;
        }
    }
    fout<<b;
    return 0;
}