about summary refs log tree commit diff
path: root/others/other/ep.c
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-08-13 00:42:13 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-08-13 00:42:13 +0700
commitdf20bbbebb8d5951607560d358c1a19388743113 (patch)
treeac91e25ccadd2c0de75494b72022c08046fffdd8 /others/other/ep.c
parentebb579dd31a19a4d08a8e9aae97c5fc354bc3e8b (diff)
downloadcp-df20bbbebb8d5951607560d358c1a19388743113.tar.gz
Tài thầy
Diffstat (limited to 'others/other/ep.c')
-rw-r--r--others/other/ep.c52
1 files changed, 52 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+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;
+}