Cod sursa(job #849626)
| Utilizator | Data | 7 ianuarie 2013 13:55:37 | |
|---|---|---|---|
| Problema | Factorial | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.57 kb |
#include<fstream>
using namespace std;
ifstream f("factorial.in");
ofstream g("factorial.out");
int fct (int x)
{
int putere=0,k=5;
while (x/k>=1)
{
putere=x/k+putere;
k=k*5;
}
return putere;
}
int main ()
{
int p,n,x1,x2,pp,y;
f>>p;
f>>n;
x1=1;
x2=1000000000;
pp=0;
while (x1<=x2&&pp==0)
{
n=(x1+x2)/2;
y=fct(n);
if (y==p)
{
pp=1;
n=n-n%5;
}
else
if (y<p)
x1=n+1;
else
x2=n-1;
}
if (pp==0)
g<<"-1"<<"\n";
else
if (p==0)
g<<1<<"\n";
else
if (pp==1)
g<<n<<"\n";
}