program ljkkk;
type
linktype=^node;
node=record
num:integer;
link:linktype;
end;
var
n,m:integer;
i,j:integer;
root,pre:linktype;
p,q:linktype;
begin
readln(n,m);
root^.num:=1;
root^.link:=nil;
p:=root;
for i:=2 to n do
begin
new(q);
q^.num:=i;
p^.link:=q;
p:=q;
end;
pre:=p;
p^.link:=root;
p:=root;
j:=1;
while (p^.link<>p) do
begin
if (j=m) then
begin
pre^.link:=p^.link;
writeln(p^.num);
dispose(p);
p:=pre^.link;
j:=1;
end
else
begin
pre:=p;
p:=p^.link;
j:=j+1;
end;
end;
writeln(p^.num);
end.
posted on 2005-08-19 15:30
李青 阅读(1305)
评论(1) 编辑 收藏 引用