about summary refs log tree commit diff
path: root/NTU/smaca.c
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2016-10-08 09:56:43 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2016-10-08 09:56:43 +0700
commit2a7bc10f6c011d19fb3b0e73068f7e1a9c30ace0 (patch)
tree95190a32ec1c7098494849eea5a5ba6b53289585 /NTU/smaca.c
parent207cc2ae9893b0cdecd20119b9ede37f73cd4a1e (diff)
downloadcp-2a7bc10f6c011d19fb3b0e73068f7e1a9c30ace0.tar.gz
Initial commit
Diffstat (limited to 'NTU/smaca.c')
-rw-r--r--NTU/smaca.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/NTU/smaca.c b/NTU/smaca.c
new file mode 100644
index 0000000..711040a
--- /dev/null
+++ b/NTU/smaca.c
@@ -0,0 +1,61 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+long gcd(long a, long b)
+{
+	long c;
+	while (b) {
+		c = a % b;
+		a = b;
+		b = c;
+	}
+	return a;
+}
+
+int main()
+{
+	char m, n, i, j, l, val0 = 0, *val;
+	long *k, *h, x, g;
+
+	scanf("%hhd %hhd", &m, &n);
+
+	val = malloc(n);
+	for (i = 0; i < n; i++)
+		val[i] = 1;
+
+	k = malloc(m * 4);
+	for (i = 0; i < m; i++)
+		scanf("%ld", &k[i]);
+
+	h = malloc(m * 4);
+	for (i = 0; i < n; i++) {
+		memcpy(h, k, m * 4);
+
+		for (j = 0; j < m; j++) {
+			scanf("%ld", &x);
+			for (l = 0; l < m && x > 1; l++) {
+				g = gcd(h[l], x);
+				h[l] /= g;
+				x /= g;
+			}
+			if (x > 1) {
+				val[i] = 0;
+				for (j++; j < m; j++)
+					scanf("%ld", &x);
+				break;
+			}
+		}
+		
+		if (val[i])
+			val0++;
+	}
+
+	printf("%hhd\n", val0);
+	for (i = 0; i < n; i++)
+		if (val[i])
+			printf("%hhd ", i + 1);
+	puts("\b");
+
+	return 0;
+}