Pagini recente » Cod sursa (job #444424) | Cod sursa (job #939711) | Cod sursa (job #1401793) | Cod sursa (job #2866719) | Cod sursa (job #512922)
Cod sursa(job #512922)
#include<fstream>
using namespace std;
long long p,m;
int i;
ifstream f("fact.in");
ofstream g("fact.out");
int verifica(long long k)
{
int nr=0;
while(k)
{
nr=nr+k/5;
k=k/5;
}
return nr;
}
void cautarebinara(long long st,long long dr,long long x)
{
long long gasit=0;
while(st<=dr&&gasit==0)
{
m=(st+dr)/2;
if(verifica(m)==x)
{
// g<<m;
gasit=1;
}
else
if(x>verifica(m))
st=m+1;
else
dr=m-1;
//else
}
if(gasit==0)
{
m=-1;
//g<<-1;
}
}
int main()
{
f>>p;
cautarebinara(1, 999999999,p);
if(m!=-1)
{
while(m)
{
if(verifica(m)==p)
m--;
else
break;
}
g<<m+1;
}
else
g<<m;
return 0;
}