Cod sursa(job #1011203)
Utilizator | Onutu Catalin beyond_k7a | Data | 16 octombrie 2013 16:11:28 |
---|---|---|---|
Problema | Factorial | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.48 kb |
#include<iostream>
#include<fstream>
using namespace std;
long nrDeCinci(long x)
{
if(x%5!=0)
return 0;
if(x<5)
return 0;
return 1+nrDeCinci(x/5);
}
long getn(long x,long nrz)
{
nrz-=(1+nrDeCinci(x));
if(nrz == 0)
return 5*x;
if(nrz < 0)
return -1;
return getn(x+1,nrz);
}
int main()
{
long p,n;
ifstream f("fact.in");
f>>p;
f.close();
n=(p==0)?1:getn(1,p);
ofstream g("fact.out");
g<<n<<"\n";
g.close();
return 0;
}