From df20bbbebb8d5951607560d358c1a19388743113 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Sun, 13 Aug 2017 00:42:13 +0700 Subject: Tài thầy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- others/other/ep.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 others/other/ep.c (limited to 'others/other/ep.c') diff --git a/others/other/ep.c b/others/other/ep.c new file mode 100644 index 0000000..7a6b2a2 --- /dev/null +++ b/others/other/ep.c @@ -0,0 +1,52 @@ +#include +#include +#include + +int cmp(const void *x, const void *y) +{ + long z = *(long *) x - *(long *) y; + if (z < 0) + return -1; + if (z) + return 1; + return 0; +} + +int main() +{ + FILE *fi = fopen("EP.INP", "r"), *fo = fopen("EP.OUT", "w"); + char t; + long a, b, c, p[1000001], q[1000001]; + long long count; + + for (a = 1; a < 1000001; a++) { + p[a] = 1; + } + + for (a = 2; a < 1001; a++) + if (p[a] == 1) + for (b = a; b < 1000001; b += a) + p[b] *= a; + + fscanf(fi, "%hhd\n", &t); + for (; t--;) { + fscanf(fi, "%ld %ld\n", &a, &b); + b -= a - 1; + memcpy(q, p + a, b * sizeof(long)); + qsort(q, b, sizeof(long), cmp); + count = 0; + + for (a = c = 1; a < b; a++) + if (q[a] != q[a - 1]) { + count += c * (c - 1) / 2; + c = 1; + } else { + c++; + } + fprintf(fo, "%Ld\n", count); + } + + fclose(fi); + fclose(fo); + return 0; +} -- cgit 1.4.1