Pagini recente » Cod sursa (job #1294431) | Cod sursa (job #138259) | Cod sursa (job #1926324) | Cod sursa (job #2323640) | Cod sursa (job #1324869)
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int n,i,j,p;
int cautbin(long long a,long long b)
{
if(a>b)
return -1;
int m=(a/5+b/5)/2;
m*=5;
int x=5;
int pa,pb,pm;
pa=pb=pm=0;
while(a/x!=0)
{
pa+=a/x;
x*=5;
}
x=5;
while(b/x!=0)
{
pb+=b/x;
x*=5;
}
x=5;
while(m/x!=0)
{
pm+=m/x;
x*=5;
}
x=5;
if(pm>n)
return cautbin(a,m-5);
else
if(pm<n)
return cautbin(m+5,b);
else
return m;
}
int main()
{
f>>n;
if(n==0)
g<<"1"<<'\n';
else
{
g<<cautbin(0,n*5)<<'\n';
}
return 0;
}