From 250b7d75204bb18311f51d8b67164f9ad4cef9f2 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Sun, 30 Oct 2016 16:37:10 +0700 Subject: NTU: Add luth2.c and TutOnEqua.c --- NTU/TutOnEqua.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 NTU/TutOnEqua.c (limited to 'NTU/TutOnEqua.c') 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 + +#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; +} -- cgit 1.4.1