Cod sursa(job #3209036)
Utilizator | Data | 1 martie 2024 18:59:33 | |
---|---|---|---|
Problema | GFact | Scor | 15 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("gfact.in");
ofstream fout("gfact.out");
int main()
{
int 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;
}