Virtual Object
::
Programs
:: Разбиение числа на слагаемые |
||||
Наша кнопка |
||||
Разбиение числа на слагаемые {$APPTYPE CONSOLE} var n,i,now:longint; a:array[1..1000] of longint; ⁄⁄---------------------------------------------------- procedure next; var i,sum:longint; begin i:=now-1; if i<=0 then begin now:=0; exit; end; sum:=a[now]; while not(((a[i-1]>a[i]) or (i=1))) do begin inc(sum,a[i]); dec(i); end; inc(a[i]); now:=i+sum-1; for i:=i+1 to now do a[i]:=1; end; ⁄⁄---------------------------------------------------- begin assign(input,′input.txt′);reset(input); assign(output,′output.txt′);rewrite(output); readln(n); fillchar(a,sizeof(a),0); for i:=1 to n do a[i]:=1; now:=n; repeat for i:=1 to now-1 do write(a[i],′ + ′); writeln(a[now]); next; until now=0; end. |
||||
Object © 2004 - 2005. All rights reserved. |