Pagini recente » Cod sursa (job #2934557) | Cod sursa (job #329527) | Cod sursa (job #3039982) | Cod sursa (job #639359) | Cod sursa (job #2444717)
#include <bits/stdc++.h>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long p;
int functie_magica(int n)
{
int s=0,p=5;
while(n>=p)
{
s+=n/p;
p*=5;
}
return s;
}
int cautare_binara(int st, int dr, int p)
{
int mij=(st+dr)/2,poz=-1;
while(st<=dr)
{
mij=(st+dr)/2;
if(functie_magica(mij)==p)
{
poz=mij;
dr=mij-1;
}
else if(functie_magica(mij)>p)dr=mij-1;
else st=mij+1;
}
return poz;
}
int main()
{
f>>p;
g<<cautare_binara(1,500000000,p);
return 0;
}