Cod sursa(job #2507190)
| Utilizator | Data | 9 decembrie 2019 19:14:49 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.8 kb |
#include <fstream>
#include <climits>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int n,p,st,dr,mij,gasit;
int zerouri(int x)
{
int s=0,putere=5;
while(x>=putere)
{
s+=x/putere;
putere*=5;
}
return s;
}
int main()
{
fin>>p;
if(p==0) fout<<1;
else
{
st=1;dr=500000000;
while(st<=dr)
{
mij=st+(dr-st)/2;
int p1=zerouri(mij);
if(p==p1)
{
gasit=1;n=mij;break;
}
else if(p<p1)
dr=mij-1;
else
st=mij+1;
}
if(!gasit)fout<<-1;
else fout<<n-n%5;
}
}
