Cod sursa(job #1268626)
| Utilizator | Data | 21 noiembrie 2014 09:51:18 | |
|---|---|---|---|
| Problema | Factorial | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.65 kb |
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int sol=-1,p;
int nrcif(long long x)
{
int k=0,j=5;
while(j<=x)
{
k=k+x/j;
j*=5;
}
return k;
}
void cautbin(long long st, long long dr)
{ int n;
long long m;
while (st<=dr)
{
m=(st+dr)/2;
n=nrcif(m);
if(n<p)
cautbin(m+1,dr);
else if(n>p)
cautbin(st, m-1);
else
{
sol=m;
cautbin(st,m-1);
}
}
}
int main()
{
f>>p;
long long st=1, dr=1000;
cautbin(st,dr);
g<<sol;
return 0;
}
