讨论 / 求大神找错
noble_ 2016-11-12 01:52:53
点我顶贴 收藏 删除
var i,i2,g,sum,n:longint;

k:shortint;

bit:array[1..100]of shortint;//记录数的二次方的每个数位

function fang(a,b:longint):longint; //求a的b次方

var a2:longint;

begin

a2:=a;

for i:=1 to b do

a:=a*a2;

exit(a);

end;

procedure er(c:longint); //求c的二进制(倒序的)

begin

g:=0;//record times

while c<>0 do

begin

inc(g);

bit[g]:=c mod 2;

c:=c div 2;

end;

end;

begin

read(k,n);

er(n);

sum:=1;

i2:=0;

for i:=g downto 1 do//倒序处理bit

begin

inc(i2);

if bit[i]=1 then begin

if i2=1 then continue;//已将sum赋值1,所以无需计算0次方了

sum:=fang(k,i2)+sum;

end;

end;

write(sum);

end.

查看更多回复
提交回复