观察可得,最大的拆分方法是尽量拆成3,特殊的,如果最后剩下了1,那么就把3+1变成2+2
然后高精度计算即可
1 var s2,s3,i,n,l:longint; 2 a:array[0..5010] of longint; 3 4 procedure mul(x,m:longint); 5 var i,j,c,y:longint; 6 begin 7 for i:=1 to m do 8 begin 9 inc(l); 10 c:=0; 11 for j:=1 to l do 12 begin 13 y:=a[j]*x+c; 14 c:=y div 10; 15 a[j]:=y mod 10; 16 end; 17 while a[l]=0 do dec(l); 18 end; 19 end; 20 21 begin 22 readln(n); 23 if n mod 3=0 then s3:=n div 3 24 else if n mod 3=1 then 25 begin 26 s3:=(n-4) div 3; 27 s2:=2; 28 end 29 else if n mod 3=2 then 30 begin 31 s3:=(n-2) div 3; 32 s2:=1; 33 end; 34 a[1]:=1; 35 l:=1; 36 mul(3,s3); 37 mul(2,s2); 38 writeln(l); 39 for i:=l downto l-99 do 40 begin 41 if i<=0 then break; 42 write(a[i]); 43 end; 44 writeln; 45 end.