Cod sursa(job #673272)
Utilizator | Data | 4 februarie 2012 11:08:13 | |
---|---|---|---|
Problema | Factorial | Scor | 40 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.38 kb |
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long P,x,i,y,j,z;
int main()
{f>>P;
if(P==0)
g<<'1';
else
{x=5*P;
while(x>0)
{x=x/5;
i=i+x;
}
x=5*P;
while(i>P)
{y=x;
j=0;
while(y%5==0&&z==0)
{z=y%5;
y=y/5;
j=j++;
}
x=x-5;
i=i-j;
}
if(i==P)
g<<x;
else
g<<"-1";}
return 0;
}