我的:program sequence;
var
sum,l:int64;
i,j,n,k:integer;
a:array [0..20]of integer;
begin
assign(input,'sequence.in');
assign(output,'sequence.out');
reset(input);
rewrite(output);
readln(k,n);
j:=0;
while n>0 do
begin
a[j]:=n mod 2;
n:=n div 2;
inc(j);
end;
l:=1;
sum:=0;
for i:=0 to j do
begin
inc(sum,l*a[i]);
l:=l*k;
end;
write(sum);
close(input);
close(output);
end.
标程:Program sequence ( Input , Output ) ;
Type
Int = Integer ;
Long = Longint ;
Var
i , j , k , n : Longint ;
w : Int64 ;
t : Longint ;
c : Array [ 0 .. 10000 ] of Integer ;
Begin
Assign ( Input , 'sequence.in' ) ;
Reset ( Input ) ;
Assign ( Output , 'sequence.out' ) ;
Rewrite ( Output ) ;
Readln ( k , n ) ;
Fillchar ( c , sizeof ( c ) , 0 ) ;
j := 0 ;
While n > 0 do
Begin
c [ j ] := n mod 2 ;
n := n div 2 ;
Inc ( j ) ;
End ;
t := 0 ;
w := 1 ;
For i := 0 to j do
Begin
Inc ( t , w * c [ i ] ) ;
w := w * k ;
End ;
Writeln ( t ) ;
Close ( Input ) ;
Close ( Output ) ;
End .