Pagini recente » Cod sursa (job #2959038) | Cod sursa (job #2690382) | Cod sursa (job #2635007) | Cod sursa (job #2715161) | Cod sursa (job #2550298)
#include <iostream>
#include <fstream>
#include <limits>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
#define LL long long int
#define ULONG_MAX 4 * 4294967295
int main() {
LL P;
LL N = 0, countP = 0, pow5 = 1;
fin >> P;
while (N < ULONG_MAX) {
N += 4 * pow5;
countP += (pow5 - 1);
pow5 *= 5;
}
pow5 /= 5;
for (; pow5 > 0; pow5 /= 5) {
if (countP == P)
break;
if (countP - (pow5 - 1) / 4 >= P) {
countP -= (pow5 - 1) / 4;
N -= pow5;
if (countP - (pow5 - 1) / 4 >= P) {
countP -= (pow5 - 1) / 4;
N -= pow5;
if (countP - (pow5 - 1) / 4 >= P) {
countP -= (pow5 - 1) / 4;
N -= pow5;
if (countP - (pow5 - 1) / 4 >= P) {
countP -= (pow5 - 1) / 4;
N -= pow5;
}
}
}
}
}
if (P != 0) {
if (countP != P) {
fout << -1;
} else {
N -= 4;
fout << N;
}
} else {
fout << 1;
}
return 0;
}