Pagini recente » Cod sursa (job #87306) | Cod sursa (job #3178134) | Cod sursa (job #1756428) | Cod sursa (job #2834657) | Cod sursa (job #1655830)
#include <fstream>
#include <iostream>
using namespace std;
long long f(long long nr);
int main() {
ifstream in("fact.in");
long long n, p = 0, q = (1ll << 60);
in >> n;
while (q > 0) {
if ( f(p + q) < n )
p += q;
q /= 2;
}
p++;
if ( f(p) != n ) {
ofstream out("fact.out");
out << -1 << ' ' << p;
return 0;
}
ofstream out("fact.out");
out << p;
return 0;
}
long long f(long long nr) {
long long r = 0;
nr /= 5;
while (nr > 0) {
r += nr;
nr /= 5;
}
return r;
}