about summary refs log tree commit diff
path: root/others/volume1/022.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/022.pas
parent7ebfa64719d4ac86b30075c65f21eafe9097853e (diff)
downloadcp-b7e55e6510690093d61f9cc1152e0330e55fe90b.tar.gz
Update others/volume1
Diffstat (limited to 'others/volume1/022.pas')
-rw-r--r--others/volume1/022.pas31
1 files changed, 31 insertions, 0 deletions
diff --git a/others/volume1/022.pas b/others/volume1/022.pas
new file mode 100644
index 0000000..87c1d15
--- /dev/null
+++ b/others/volume1/022.pas
@@ -0,0 +1,31 @@
+var
+  s: array[1..1000000] of int32;
+  m, n, i, j: int32;
+
+begin
+  readln(m);
+  s[1] := 0;
+  for i := 2 to m do
+    begin
+      n := trunc(sqrt(i));
+      if i mod n > 0 then
+        s[i] := 1
+      else if i = n * n then
+        s[i] := 1 + n
+      else
+        s[i] := 1 + n + i div n;
+      for j := 2 to n - 1 do
+        if i mod j = 0 then
+          inc(s[i], j + i div j)
+    end;
+
+  j := 0;
+  for i := 2 to m do
+    if (i <> s[i]) and
+       (s[i] <= 1000000) and
+       (i = s[s[i]]) then
+      begin writeln(i, ' ', s[i]);
+      inc(j);
+    end;
+  writeln(j div 2)
+end.