- 2的幂次方
- 2009-10-14 21:42:40 @
var
a:array[0..20]of boolean;
i,k,n,t:integer;
procedure print(n:integer);
begin
case n of
0:write('0');
1:write('2(0)');
2:write('2');
3:write('2+2(0)');
4:write('2(2)');
5:write('2(2)+2(0)');
6:write('2(2)+2');
7:write('2(2)+2+2(0)');
8:write('2(2+2(0))');
9:write('2(2+2(0))+2(0)');
10:write('2(2+2(0))+2');
11:write('2(2+2(0))+2+2(0)');
12:write('2(2+2(0))+2(2)');
13:write('2(2+2(0))+2(2)+2(0)');
14:write('2(2+2(0))+2(2)+2');
end;
end;
begin
readln(n);
k:=-1; t:=-1;
fillchar(a,sizeof(a),false);
while n>0 do
begin
inc(k);
if odd(n) then a[k]:=true;
if (t=-1)and(odd(n)) then t:=k;
n:=n div 2;
end;
for i:= k downto t do
if a[i] then
begin
write('2('); print(i); write(')');
if it then write('+');
end;
end.
一组错误,一组长了
2 条评论
-
沉默々泽 LV 8 @ 2009-10-31 10:56:40
谢谢
可我在看之前已经AC了,呵呵……
-
2009-10-29 21:01:09@
因为当写2^1的时候应该写2,但是你那样的话会写2(2(0))
- 1