about summary refs log tree commit diff
path: root/others/volume1/009.pas
blob: 67f57b1b446a5a0ee5383a9bba61b2a01aaf0b90 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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.