Cod sursa(job #302432)
Utilizator | Rosca Valentin valentinrosca | Data | 8 aprilie 2009 21:32:45 |
---|---|---|---|
Problema | Factorial | Scor | 5 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.4 kb |
#include<math.h>
#include<fstream.h>
ifstream fin("fact.in");
ofstream fout("fact.out");
long p,n,i,j,x;
int main()
{
fin>>p;
if(p)
{
n=5;
do
{
n=n+5;
i=0;
x=0;
do
{
i++;
}
while(pow(5,i)<=n);
i--;
for(j=1;j<=i;j++)
x=x+n/(long)pow(5,i);
}
while(x<p);
if(x>p)
fout<<"-1";
else
fout<<n;
}
else
fout<<"1";
return 0;
}