Pagini recente » Cod sursa (job #583304) | Cod sursa (job #183093) | Cod sursa (job #69105) | Cod sursa (job #2358684) | Cod sursa (job #2295077)
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p;
int fact(int n)
{ int i,val=0;
for(i=5; n/i>=1; i*=5)
val+=n/i;
return val;
}
int main()
{ fin>>p;
if(p==0) {fout<<1; return 0;}
else if(p==1) {fout<<5; return 0;}
long long s=0,d=5*p;
int pp=0;
long long m=-1;
while(s<d )
{ m=(s+d)/2;
if(fact(m)==p) d=m;
else s=m+1;
}
fout<<m;
return 0;
}