Pagini recente » Cod sursa (job #2330218) | Cod sursa (job #107891) | Cod sursa (job #3228549) | Cod sursa (job #1279149) | Cod sursa (job #1452471)
#include <iostream>
#include <fstream>
#include <cmath>
#define MIN(a,b) ((a)<(b))?(a):(b)
const char IN[] = "fact.in", OUT[] = "fact.out";
using namespace std;
int P;
inline void read_data() {
fscanf(fopen(IN, "r"), "%d", &P);
}
int perm_count_zeros(int x) {
int total = 0;
for (int b5 = 5, cnt = -1; cnt != 0; b5 *= 5) {
cnt = floor(x/b5);
total += cnt;
}
return total;
}
inline int find_fact(int P) {
if (P == 0) return 1;
int low = 1, high = 100000000;
while (low < high) {
int m = low + (high - low) / 2;
int count = perm_count_zeros(m);
if (count == P && perm_count_zeros(m-1) != P) return m;
if (count < P) low = m + 1;
else high = m - 1;
}
}
int main() {
read_data();
printf("%d\n", perm_count_zeros(4617));
fprintf(fopen(OUT, "w"), "%d\n", find_fact(P));
return 0;
}