From f4f486fb4b37b72ca345f95881e44043c728b2c3 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Tue, 10 Jan 2017 10:46:15 +0700 Subject: Add others/other --- others/other/fdp.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 others/other/fdp.c (limited to 'others/other/fdp.c') diff --git a/others/other/fdp.c b/others/other/fdp.c new file mode 100644 index 0000000..439716b --- /dev/null +++ b/others/other/fdp.c @@ -0,0 +1,50 @@ +#include +#include + +int main() +{ + FILE *F = fopen("FDP.INP", "r"); + long long n, m, j, factors[11]; + long i; + char f = 0, fm[11] = {}, fn[11] = {}, k = 127; + + fscanf(F, "%lld %lld", &n, &m); + fclose(F); + + if (m % 2 == 0) { + factors[0] = 2; + do { + m /= 2; + fm[0]++; + } while (m % 2 == 0); + f = 1; + } + + for (i = 3; i <= (long) sqrt((double) m); i += 2) + if (m % i == 0) { + factors[f] = i; + do { + m /= i; + fm[f]++; + } while (m % i == 0); + f++; + } + + if (m != 1) { + factors[f] = m; + fm[f] = 1; + f++; + } + + for (i = 0; i < f; i++) { + for (j = factors[i]; j <= n; j *= factors[i]) + fn[i] += n / j; + k = (fn[i] / fm[i] < k) ? (fn[i] / fm[i]) : k; + } + + F = fopen("FDP.OUT", "w"); + fprintf(F, "%hhd\n", k); + fclose(F); + + return 0; +} -- cgit 1.4.1