Pagini recente » Cod sursa (job #2714507) | Cod sursa (job #411147) | Cod sursa (job #1158788) | Cod sursa (job #1660812) | Cod sursa (job #2525192)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
const int Nmax = 500000000;
int n, p;
void BinSearch(int l, int r){
if (l > r)
return;
int mid = (l + r) >> 1;
int x = 5, s = 0;
while (x <= mid){
s += mid / x;
x *= 5;
}
if (s == p)
n = mid;
if (s < p)
BinSearch(mid + 1, r);
else
BinSearch(l, mid - 1);
}
int main(){
fin >> p;
n = -1;
BinSearch(1, Nmax);
fout << n << '\n';
return 0;
}