about summary refs log tree commit diff
path: root/others/volume1/004.pas
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-11 11:37:48 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-11 11:37:48 +0700
commitdf9a0d140a7b7edef66f95aa13b5bb4488147f68 (patch)
treede213e8e6abf244426fcec5974c1cc247897f869 /others/volume1/004.pas
parent092019121ad5ef6f82cd8fe7bf6ee143fce9648d (diff)
downloadcp-df9a0d140a7b7edef66f95aa13b5bb4488147f68.tar.gz
Fast and furiously add others/volume1
Diffstat (limited to 'others/volume1/004.pas')
-rw-r--r--others/volume1/004.pas33
1 files changed, 33 insertions, 0 deletions
diff --git a/others/volume1/004.pas b/others/volume1/004.pas
new file mode 100644
index 0000000..caf5142
--- /dev/null
+++ b/others/volume1/004.pas
@@ -0,0 +1,33 @@
+var
+  prime: array [2..1000000] of boolean;
+  i, j, n, k: longint;
+  b: boolean = true;
+
+begin
+  for i := 2 to 1000000 do
+    prime[i] := true;
+  for i := 2 to 1000 do
+    if prime[i] then
+      for j := i to 1000000 div i do
+        prime[i * j] := false;
+
+  readln(n, k);
+  if n < 2 then
+    writeln('FALSE')
+  else if n <= 1000000 then
+    writeln(prime[n])
+  else
+    begin
+      for i := 2 to trunc(sqrt(n)) do
+        if n mod i = 0 then
+        begin
+          b := false;
+          break
+        end;
+      writeln(b)
+    end;
+  for i := 2 to k do
+    if prime[i] then
+      write(i, ' ');
+  writeln
+end.