Pagini recente » Cod sursa (job #2627773) | Borderou de evaluare (job #2983670) | Cod sursa (job #2555017) | Cod sursa (job #346389) | Cod sursa (job #980486)
Cod sursa(job #980486)
#include<fstream>
using namespace std;
long long zero(int x)
{
int nr=0,d=5;
while (d<=x)
{
nr+=x/d;
d*=5;
}
return nr;
}
long long binary_search(int low,int high,int value)
{
long long mid,nr_zero;
while (low<=high)
{
mid=low+((high-low)>>1);
nr_zero=zero(mid);
if (nr_zero==value)
{
int aux=mid-1;
while (zero(aux)==value && aux>=0)
--aux;
return aux+1;
}
else if (value<nr_zero)
high=mid-1;
else if (value>nr_zero)
low=mid+1;
}
return -1;
}
int main()
{
int p;
ifstream fin("fact.in");
fin>>p;
fin.close();
ofstream fout("fact.out");
fout<<binary_search(1,488281250,p);
fout.close();
return 0;
}