Pagini recente » Cod sursa (job #2962467) | Cod sursa (job #1269781) | Cod sursa (job #2631477) | Cod sursa (job #2658635) | Cod sursa (job #2069493)
#include <fstream>
#include<limits>
#define Maxim INT_MAX
using namespace std;
int p;
long long NrZeroes(int x)
{
long long putere=5,suma=0;
while(putere<=x)
{suma+=x/putere;putere*=5;}
return suma;
}
int cautbin(int left,int right,int val)
{
int st=left,dr=right,LastApp;
while(st<=dr)
{
int mij=(dr-st)/2+st;
long long fct=NrZeroes(mij);
if(fct<p){st=mij+1;continue;}
if(fct>p){dr=mij-1;continue;}
LastApp=mij;
dr=mij-1;
}
return LastApp;
}
int main()
{
ifstream f("fact.in");
ofstream g("fact.out");
f>>p;
g<<cautbin(1,Maxim,p)<<'\n';
return 0;
}