Cod sursa(job #1655830)
Utilizator | Data | 18 martie 2016 13:13:56 | |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.58 kb |
#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;
}