Cod sursa(job #2908719)
| Utilizator | Data | 5 iunie 2022 13:43:43 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.62 kb |
#include <fstream>
using namespace std;
ifstream fin ("fact.in");
ofstream fout ("fact.out");
long long p,st,dr,mij,x,p5,s;
int main()
{
fin>>p;
st=1;
dr=p*5;
while (st<=dr)
{
mij=(st+dr)/2;
x=mij;
p5=5;
s=0;
while (p5<=x)
{
s=s+x/p5;
p5=p5*5;
}
if (s<p)
st=mij+1;
else
dr=mij-1;
}
p5=5;
s=0;
x=st;
while (p5<=x)
{
s=s+x/p5;
p5=p5*5;
}
if (s==p)
fout<<st;
else
fout<<-1;
return 0;
}
