about summary refs log tree commit diff
path: root/NTU/ngto4.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/ngto4.c
parent207cc2ae9893b0cdecd20119b9ede37f73cd4a1e (diff)
downloadcp-2a7bc10f6c011d19fb3b0e73068f7e1a9c30ace0.tar.gz
Initial commit
Diffstat (limited to 'NTU/ngto4.c')
-rw-r--r--NTU/ngto4.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/NTU/ngto4.c b/NTU/ngto4.c
new file mode 100644
index 0000000..02237b6
--- /dev/null
+++ b/NTU/ngto4.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <math.h>
+
+#define idx(n) (n - 1) / 2 - 1
+
+long primes[1000000];
+
+int main()
+{
+	long i, j;
+	char pdict[500001] = {[0 ... 500000] = 1};
+	for (i = 3; i < 1000; i += 2)
+		if (pdict[idx(i)])
+			for (j = i * i; j < 1000000; j += i * 2)
+				pdict[idx(j)] = 0;
+
+	primes[0] = 2;
+	j = 0;
+	for (i = 3; i < 1000000; i += 2)
+		if (pdict[idx(i)])
+			primes[++j] = i;
+
+	printf("%ld ", primes[78497]);
+	printf("\n%ld\n", j);
+
+	return 0;
+}