about summary refs log tree commit diff
path: root/others/volume1/009.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/009.pas
parent092019121ad5ef6f82cd8fe7bf6ee143fce9648d (diff)
downloadcp-df9a0d140a7b7edef66f95aa13b5bb4488147f68.tar.gz
Fast and furiously add others/volume1
Diffstat (limited to 'others/volume1/009.pas')
-rw-r--r--others/volume1/009.pas34
1 files changed, 34 insertions, 0 deletions
diff --git a/others/volume1/009.pas b/others/volume1/009.pas
new file mode 100644
index 0000000..67f57b1
--- /dev/null
+++ b/others/volume1/009.pas
@@ -0,0 +1,34 @@
+var
+  n, i, tmp: longint;
+  a: array of longint;
+
+begin
+  readln(n);
+  if n > 1 then
+    setlength(a, trunc(sqrt(n * 2 + 2.25) - 1.5))
+  else
+    setlength(a, 1);
+  tmp := 0;
+  for i := 0 to length(a) - 2 do
+    begin
+      a[i] := i + 2;
+      inc(tmp, a[i])
+    end;
+  a[length(a) - 1] := n - tmp;
+
+  if length(a) > 1 then
+    while a[length(a) - 1] - a[length(a) - 2] > 2 do
+      for i := length(a) - 1 downto 1 do
+        begin
+          tmp := (a[i] - 1 - a[i - 1]) div 2;
+          if tmp > 0 then
+            begin
+              dec(a[i], tmp);
+              inc(a[i - 1], tmp)
+            end
+        end;
+
+  for i in a do
+    write(i, ' ');
+  writeln
+end.