Cod sursa(job #1943282)
Utilizator | Lupulescu Vlad lupulescu2001 | Data | 28 martie 2017 14:46:55 |
---|---|---|---|
Problema | Factorial | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.63 kb |
#include<fstream>
using namespace std;
ifstream fin("factorial.in");
ofstream fout("factorial.out");
int a[5000003],p;
bool check(int val)
{
int s=0,x,f=5;
x=val;
while(x/f!=0)
{
s=s+x/f;
f=f*5;
}
if(s>=p)
return true;
else
return false;
}
int cautbin()
{
int l=1,r=5000003,sol,mid;
while(l<=r)
{
mid=(l+r)/2;
if(check(a[mid])==1)
{
sol=a[mid];
r=mid-1;
}
else
l=mid+1;
}
return sol;
}
int main()
{int i;
fin>>p;
for(i=1;i<=5000000;i++)
a[i]=i;
fout<<cautbin();
}