Accepted
/usr/bin/ld.bfd: warning: /out/link.res contains output sections; did you forget -T?
代码
var n,m,i:longint;
a:array[0..500000]of longint;
u:array[0..10000000]of boolean;
begin
readln(n);
fillchar(u,sizeof(u),false);
a[0]:=0; a[1]:=1;
u[0]:=true; u[1]:=true;
m:=2;
while m<=n do begin
if (a[m-1]-m>0)and(u[a[m-1]-m]=false)
then begin a[m]:=a[m-1]-m; u[a[m]]:=true;end
else begin a[m]:=a[m-1]+m; u[a[m]]:=true;end;
inc(m);
end;
writeln(a[n]);
close(input);
close(output);
end.