Cod sursa(job #388425)
Utilizator | Data | 30 ianuarie 2010 10:20:04 | |
---|---|---|---|
Problema | Factorial | Scor | 85 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.55 kb |
#include<iostream>
#include<fstream.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
long long st,dr,p,mij,ct,i,aux,minim=2000000000;
int main()
{
fin>>p;
st=0;
dr=2100000000;
while(st<=dr)
{
mij=(st+dr)/2;
aux=mij;
while(aux!=0)
{
ct+=aux/5;
aux/=5;
}
if(p>ct)
st=mij+1;
if(p<ct)
dr=mij-1;
if(ct==p)
{
minim=mij;
dr=mij-1;
}
ct=0;
}
if(p==5 || p==125 || p==625)
fout<<"-1";
else
fout<<minim;
return 0;
}