Cod sursa(job #979718)
| Utilizator | Data | 2 august 2013 16:10:56 | |
|---|---|---|---|
| Problema | Factorial | Scor | 25 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.63 kb |
#include<fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long p,c;
int put(int m)
{
int n=5,z=0;
while(n<=m)
{
z=z+m/n;
n*=5;
}
return z;
}
int caut(int a,int b,int k)
{
int i;
i=(a+b)/2;
if(a>b) return 0;
else
if (put(i)==k && i%5==0)
return i;
else
if(put(i)>p)
return caut(a,i-1,p);
else
return caut(i+1,b,p);
}
int main()
{
f>>p;
if(p==0)
c=1;
else
c=caut(0,5*p,p);
if(c==0)
g<<-1<<"\n";
else
g<<c<<"\n";
g.close();
f.close();
return 0;
}
