about summary refs log tree commit diff
path: root/NTU/TutOnEqua.c
diff options
context:
space:
mode:
Diffstat (limited to 'NTU/TutOnEqua.c')
-rw-r--r--NTU/TutOnEqua.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/NTU/TutOnEqua.c b/NTU/TutOnEqua.c
new file mode 100644
index 0000000..84cec70
--- /dev/null
+++ b/NTU/TutOnEqua.c
@@ -0,0 +1,55 @@
+#include <stdio.h>
+
+#define abs(x) (x < 0) ? -x : x
+
+int gcd(int a, int b)
+{
+	int c;
+
+	while (b) {
+		c = a % b;
+		a = b;
+		b = c;
+	}
+
+	return a;
+}
+
+int main()
+{
+	int a, b, c, i, j, k, l, m, n, t;
+	char solutions[201][100];
+
+	scanf("%d", &t);
+	for (i = t; i; i--) {
+		for (k = 0; k < 201; k++)
+			for (l = 0; l < 100; l++)
+				solutions[k][l] = 0;
+
+		scanf("%d", &n);
+		for (j = n; j; j--) {
+			scanf("%d %d", &a, &b);
+			if (a) {
+				c = gcd(a, b);
+
+				if (a * b < 0)
+					a = -abs(a / c) + 100;
+				else
+					a = abs(a / c) + 100;
+				b = abs(b / c) - 1;
+
+				solutions[a][b] = 1;
+			}
+		}
+
+		m = 0;
+		for (j = 0; j < 201; j++)
+			for (k = 0; k < 100; k++)
+				if (solutions[j][k])
+					m++;
+
+		printf("%d\n", m);
+	}
+
+	return 0;
+}