Cod sursa(job #139999)
| Utilizator | Data | 20 februarie 2008 23:27:36 | |
|---|---|---|---|
| Problema | Factorial | Scor | 15 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.47 kb |
#include <fstream.h>
#include <math.h>
ifstream f("fact.in");
ofstream g("fact.out");
long n,s,k,li,ls,gasit,n_aux;
int main()
{ f>>k;
li=0;ls=10000015;gasit=0;
while (li!=ls){
n_aux=n=(li+ls)/2;
s=0;
while (n!=0)
{s+=n/5;
n=n/5;
}
if (s<k) li=(li+ls)/2+1;
else if (s>k) ls=ls/2;
else {gasit=1;break;}
}
if (k==0) g<<1;
else {
n_aux=n_aux/5*5;
if (gasit) g<<n_aux;
else g<<"-1";}
f.close();
g.close();
return 0;
}