Mai intai trebuie sa te autentifici.
Cod sursa(job #390874)
| Utilizator | Data | 4 februarie 2010 18:40:55 | |
|---|---|---|---|
| Problema | Factorial | Scor | 95 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.89 kb |
#include<fstream>
using namespace std;
unsigned long int nrz(unsigned long int x)
{
int y=0;
while(x!=0)
{
x=x/5;
y=y+x;
}
return y;
}
void sol(unsigned long int a,unsigned long int p,unsigned long int b,unsigned long int &s)
{
unsigned long int m;
if(b>a)
{
m=(a+b)/2;
if(nrz(m)==p)
s=m;
else
if(nrz(m)<p)
sol(m+1,p,b,s);
else
sol(a,p,m-1,s);
}
}
int main()
{
ifstream f("fact.in");
ofstream g("fact.out");
unsigned long int p,s=0,c;
f>>p;
sol(0,p,1000000000,s);
if(s==0)
g<<-1;
else
{
c=s-1;
while(nrz(c)==p)
c--;
g<<c+1;}
return 0;
}
