const JINDU = 100000; var n: Integer; //在数字前补0 procedurePrintANumber(x: longint); var t: longint; begin if x = 0then write('00000') else begin t := JINDU; while t > x * 10do begin write(0); t := t div10; end; write(x); end; end;
var ans: array [1..300] of longint; len, i: integer; //计算2^(n-1) procedurecalc2; var i, x, t, mul: longint; begin len := 1; ans[1] := 1; t := n-1; while t > 0do begin if t < 6then mul := 1 << t else mul := 64; x := 0; for i := 1to len do begin ans[i] := ans[i] * mul + x; x := ans[i] div JINDU; ans[i] := ans[i] mod JINDU; end; if x > 0then begin inc(len); ans[len] := x; end; dec(t, 6); end; end; //除以3 procedurediv3; var i, x, t: longint; begin i := len; x := 0; while i > 0do begin t := (x * JINDU + ans[i]); ans[i] := t div3; x := t mod3; dec(i); end; while ans[len] = 0do dec(len); end;
begin assign(input, 'main.in'); reset(input); assign(output, 'main.out'); rewrite(output);
whilenot eof do begin readln(n); if n=1then//特殊情况处理 begin writeln(0); continue; end; fillchar(ans, sizeof(ans), 0); calc2; if odd(n) then dec(ans[1]) else inc(ans[1]); div3; write(ans[len]); for i := len-1downto1do PrintANumber(ans[i]); writeln; end;
OOPS!
A comment box should be right here...But it was gone due to network issues :-(If you want to leave comments, make sure you have access to disqus.com.