From df9a0d140a7b7edef66f95aa13b5bb4488147f68 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Sat, 11 Feb 2017 11:37:48 +0700 Subject: Fast and furiously add others/volume1 --- others/volume1/009.pas | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 others/volume1/009.pas (limited to 'others/volume1/009.pas') 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. -- cgit 1.4.1