about summary refs log tree commit diff
path: root/2ndary/12/Q-VĩnhTường-2006/cau2.c
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2020-06-06 21:33:13 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2020-06-06 21:33:13 +0700
commit2f674dc80f0382f1c3178f435714960734dc9d3c (patch)
tree2abba7e4ec72bd16f58f7375126144d3fd9f4bca /2ndary/12/Q-VĩnhTường-2006/cau2.c
parentb2d80610db6beda38573890ed169815e495bc663 (diff)
downloadcp-2f674dc80f0382f1c3178f435714960734dc9d3c.tar.gz
Reorganize stuff from secondary school
Diffstat (limited to '2ndary/12/Q-VĩnhTường-2006/cau2.c')
-rw-r--r--2ndary/12/Q-VĩnhTường-2006/cau2.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/2ndary/12/Q-VĩnhTường-2006/cau2.c b/2ndary/12/Q-VĩnhTường-2006/cau2.c
new file mode 100644
index 0000000..4ad1c3b
--- /dev/null
+++ b/2ndary/12/Q-VĩnhTường-2006/cau2.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <math.h>
+
+char prime(unsigned long long m)
+{
+	unsigned long i;
+
+	for (i = 3; i <= sqrt(m); i += 2)
+		if (m % i == 0)
+			return 0;
+
+	return 1;
+}
+
+int main()
+{
+	unsigned long long n, i;
+
+	scanf("%lld", &n);
+
+	if (n == 1) {
+		puts("2");
+
+		return 0;
+	}
+
+	i = (n % 2) ? n : n - 1;
+
+	while (i <= 18446744073709551615ULL) {
+		i += 2;
+
+		if (!prime(i))
+			continue;
+
+		printf("%lld\n", i);
+
+		return 0;
+	}
+}