Cod sursa(job #3153964)
Utilizator | Data | 2 octombrie 2023 15:15:49 | |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.47 kb |
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int main()
{
int p,n,st,k,dr,s=0,mij,x,sol=-1;
fin>>p;
dr=p*5;
st=1;
while(st<=dr)
{
mij=(st+dr)/2;s=0;
x=mij;k=5;
while(k<=x)
{
s=s+x/k;
k=k*5;
}
if(s==p){sol=mij;dr=mij-1;}
else if(s<p){st=mij+1;}
else dr=mij-1;
}if(p==0)fout<<1;
else
fout<<sol;
return 0;
}