about summary refs log tree commit diff
path: root/others/volume1/021.pas
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-28 11:34:35 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-28 11:34:35 +0700
commitb7e55e6510690093d61f9cc1152e0330e55fe90b (patch)
tree36b48f77d96adaaaefc7728c8a95ca5d4342d653 /others/volume1/021.pas
parent7ebfa64719d4ac86b30075c65f21eafe9097853e (diff)
downloadcp-b7e55e6510690093d61f9cc1152e0330e55fe90b.tar.gz
Update others/volume1
Diffstat (limited to 'others/volume1/021.pas')
-rw-r--r--others/volume1/021.pas29
1 files changed, 29 insertions, 0 deletions
diff --git a/others/volume1/021.pas b/others/volume1/021.pas
new file mode 100644
index 0000000..f20aa7c
--- /dev/null
+++ b/others/volume1/021.pas
@@ -0,0 +1,29 @@
+var
+  i, n: int32;
+
+function isperfect(n: int32): boolean;
+  var
+    i, s, m: int32;
+  begin
+    m := trunc(sqrt(n));
+    if n mod m > 0 then
+      s := 1
+    else if n = m * m then
+      s := 1 + m
+    else
+      s := 1 + m + n div m;
+    for i := 2 to m - 1 do
+      if n mod i = 0 then
+        s := s + i + n div i;
+    if s = n then
+      isperfect := true
+    else
+      isperfect := false
+  end;
+
+begin
+  readln(n);
+  for i := 2 to n do
+    if isperfect(i) then
+      writeln(i)
+end.