Cod sursa(job #1937936)
Utilizator | Data | 24 martie 2017 14:09:49 | |
---|---|---|---|
Problema | Factorial | Scor | 20 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.63 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int main()
{
int i,p,x,k=0;
fin>>p;
if(p==0)fout<<1;
else
{
i=5;
while(p>0)
{
x=p;
p-=(i*5-i)/5+k*4;
k++;
i*=5;
}
i/=5;
p=x;
while(p>0)
{
x=i;
while(x%5==0)
{
p--;
x/=5;
}
i+=5;
}
i-=5;
if(p==0)fout<<i;
else fout<<-1;
}
return 0;
}