Cod sursa(job #1943315)
Utilizator | Lupulescu Vlad lupulescu2001 | Data | 28 martie 2017 15:04:23 |
---|---|---|---|
Problema | Factorial | Scor | 90 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.63 kb |
#include<fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int 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=500000000,sol,mid;
while(l<=r)
{
mid=(l+r)/2;
if(check(mid)==1)
{
sol=mid;
r=mid-1;
}
else
l=mid+1;
}
return sol;
}
int main()
{
fin>>p;
if(p>0)
fout<<cautbin();
else
if(p==0)
fout<<1;
else
if(p<0)
fout<<-1;
}