Pagini recente » Cod sursa (job #1385415) | Cod sursa (job #1893711) | Cod sursa (job #86551) | Cod sursa (job #92465) | Cod sursa (job #1722315)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
long long int low=1,mid,high=1000000000,answer;
long long int x;
int nrzero(int n)
{
long int five=5,result=0;
while(n>=five)
{
result=result+n/five;
five=five*5;
}
return result;
}
int BinarySearch(int p)
{
answer=-1;
while(low<=high)
{
mid=low+(high-low)/2;
x=nrzero(mid);
if(x==p)
{
answer=mid;
high=mid-1;
}
else if(x<p)
{
low=mid+1;
}
else
{
high=mid-1;
}
}
return answer;
}
int main()
{
long long int p,x;
in>>p;
x=BinarySearch(p);
out<<x;
}