Pagini recente » Cod sursa (job #374266) | Cod sursa (job #1962733) | Monitorul de evaluare | Cod sursa (job #1649568) | Cod sursa (job #1097759)
#include <fstream>
using namespace std;
long p, n;
int fx(int k){
long m = 5, z = 0;
while(k/m != 0){
z += k/m;
m *= 5;
}
return z;
}
int find_N(long x, long r){
if(x > r){
return -1;
}else{
long c = (x+r)/2;
if(fx(c)<p){
find_N(c, r);
}else if(fx(c)>p){
find_N(x, c-1);
}else{
return c;
}
}
}
int main()
{
ifstream f("fact.in");
ofstream g("fact.out");
f>>p;
if(p == 0){
g<<1;
}else{
n = find_N(0, 5000000000);
while(fx(n-1)==p){
n=n-1;
}
}
g<<n;
}