about summary refs log tree commit diff
path: root/ntu/root.c
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-12-15 15:09:13 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-12-15 15:09:13 +0700
commit9e28e4c7b67c54229df11d355047ac8a88ea1817 (patch)
tree0d9d40db69613c2c49564a3f1987a005d61f4db3 /ntu/root.c
parent67393f42f41ab92219deb549f711121c4dab845b (diff)
downloadcp-9e28e4c7b67c54229df11d355047ac8a88ea1817.tar.gz
Normalize pathname
Diffstat (limited to 'ntu/root.c')
-rw-r--r--ntu/root.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/ntu/root.c b/ntu/root.c
new file mode 100644
index 0000000..01b9b30
--- /dev/null
+++ b/ntu/root.c
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+int cmp(const void *x, const void *y)
+{
+	return *(long *) x - *(long *) y;
+}
+
+int main()
+{
+	short i;
+	long a[31622]; /* square root of 1 billion */
+	for (i = 0; i < 31622; i++) {
+		a[i] = i + 1;
+		a[i] *= a[i];
+	}
+
+	short t;
+	scanf("%hd", &t);
+
+	long *n = malloc(t * sizeof(long));
+	for (i = 0; i < t; i++)
+		scanf("%ld", &n[i]);
+
+	long foo;
+	for (i = 0; i < t; i++) {
+		foo = (long) sqrt(n[i]);
+		foo *= foo;
+		foo = (long *) bsearch(&foo, a, 31622, 4, cmp) - a;
+		while ((foo > 0) && (n[i] % a[foo]))
+			foo--;
+		printf("%hd %ld\n", foo + 1, n[i] / a[foo]);
+	}
+
+	return 0;
+}