Cod sursa(job #2523240)
| Utilizator | Data | 13 ianuarie 2020 20:55:54 | |
|---|---|---|---|
| Problema | Factorial | Scor | 60 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.96 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int main()
{
long p,aux=-1,st=0,dr=100000000,s=0,i,m;
fin>>p;
if (p==0)
aux=1;
else
while(st<=dr)
{
m=(st+dr)/2;
s=0;
i=5;
while(m/i>=1)
{
s+=m/i;
i*=5;
}
if(s==p)
{
aux=m;
dr=m-1;
}
else
if(s>p) dr=m-1;
else st=m+1;
}
fout<<aux;
return 0;
}
