/QN - QN-Chính Phương

<Problem>

http://ntucoder.net/Problem/Details/4454
              Var     n,i,a:longint;
        temp:real;
        kt:array[0..31622] of boolean;
Begin
        readln(n);
        for i:=1 to n do
        begin
                read(a);
                temp:=sqrt(a);
                if (temp=trunc(temp)) then kt[trunc(temp)]:=true;
        end;
        for i:=0 to 31622 do
        if kt[i]=false then
        begin
                writeln(i*i);
                break;
        end;
End.
--------------------------
Cách 2 (Dùng con trỏ)
Uses Crt;
Type //Pnode=TNode
        Tnode=record
            info,check:longint;
            pre,link:integer;
        end;
        Tlist=array[-1..31623] of Tnode;
Var     node:Tlist;
        First,last:integer;
        n,i,d:^integer;
        c:^real;
        a:^longint;
Begin
        new(n);
        readln(n^);
        new(i);
        i^:=0;
        first:=0; last:=31622;
        while i^<=31622 do
        begin
            Node[i^].info:=i^;
            Node[i^].check:=0;
            Node[i^].pre:=i^-1;
            Node[i^].link:=i^+1;
            i^:=i^+1;
        end;
        while n^<>0 do
        begin
            new(a);
            read(a^);
            new(c); new(d);
            c^:=sqrt(a^);
            d^:=trunc(c^);
            if (frac(c^)=0) and (Node[d^].check=0) then
            With Node[d^] do
            begin
                if (Node[first].link=Node[d^].link) then
                begin
                    Node[d^].check:=1;
                    first:=Node[Node[d^].link].info;
                    Node[first].pre:=-1;
                end
                else
                begin
                    if (Node[last].link=Node[d^].link) then
                    begin
                        last:=Node[node[d^].pre].info;
                        node[last].link:=31623;
                        node[d^].check:=1;
                    end
                    else
                        begin
                            Node[Node[d^].pre].link:=Node[node[d^].link].info;
                            Node[node[d^].link].pre:=node[node[d^].pre].info;
                            Node[d^].check:=1;
                        end;
                end;
            end;
            n^:=n^-1;
        end;   //writeln('-');
        writeln(Node[first].info*Node[first].info);
        readln;

End.