Cod sursa(job #179028)
Utilizator | Data | 15 aprilie 2008 15:20:44 | |
---|---|---|---|
Problema | Factorial | Scor | 20 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.99 kb |
#include <fstream.h>
ifstream f("fact.in");
ofstream g("fact.out");
long p;
int main()
{
long a,b,c;
f>>p;
if (p==0)
g<<1;
else
{
a=5;
b=p*10;
c=(a+b)/2;
int sw=0;
long x;
long j,i;
while (a<=b && sw==0)
{
x=0;
for (j=5;j<=c;j=j+5)
{
i=j;
while (i%5==0)
{
x++;
i=i/5;
}
}
if (p==x)
{
sw=1;
while (c%5!=0)
c--;
g<<c;
}
else
if (p<x)
b=c-1;
else
a=c+1;
c=(a+b)/2;
}
if (sw==0)
g<<"-1";
}
f.close();
g.close();
}