Pagini recente » Cod sursa (job #3268005) | Cod sursa (job #925491) | Cod sursa (job #2773183) | Cod sursa (job #2230062) | Cod sursa (job #2550209)
#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 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) {
N -= 4;
fout << N;
} else {
fout << 1;
}
return 0;
}