Pagini recente » Cod sursa (job #1506206) | Cod sursa (job #445132) | Cod sursa (job #1442515) | Cod sursa (job #1813362) | Cod sursa (job #2622772)
#include<iostream>
#include<algorithm>
#include<fstream>
#include<cmath>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long P;
int nr_fact(long long x)
{
int nr = 0, p = 1, temp = 5;
while(temp <= x)
{
nr += x / temp;
p++;
temp = pow(5,p);
}
return nr;
}
long long Cautare(int l,int r)
{
if(P == 0)
return 1;
if(l == r)
if(nr_fact(l) == P)
return l;
else
return -1;
else
{
long long mid;
mid = l + (r - l)/ 2;
if(nr_fact(mid) < P)
return Cautare(mid + 1,r);
else
return Cautare(l,mid - 1);
}
}
int main()
{
f>>P;
g<<Cautare(5,P*10);
f.close();
g.close();
return 0;
}