Cod sursa(job #1653154)
| Utilizator | Data | 15 martie 2016 19:17:43 | |
|---|---|---|---|
| Problema | Factorial | Scor | 20 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.68 kb |
#include <fstream>
using namespace std;
long long int p,st,dr,rezultat,step,index,start;
long long int fact(long long int x)
{
long long int sol=0,put5=5;
while(put5<=x)
{
sol=sol+x/put5;
put5=put5*5;
}
return sol;
}
int main()
{
ifstream f("fact.in");
ofstream g("fact.out");
f>>p;
st=1;
step=1;
dr=1000000;
for(;dr>=step;step<<=1);
for(;step;step>>=1)
{
index=st+step;
if(index>dr)
continue;
else if(fact(index)<p)
{
st=index;
}
}
if(fact(st+1)==p)
g<<st+1;
else g<<-1;
}
