uses crt;
var n,j,d:word;
function so(n:word):word;
var tam:byte;
begin
so:=0;
while n>0 do
begin
tam:=n mod 10;
n:=n div 10;
so:=so+(tam*tam);
end;
end;
function snt(x:word):boolean;
var i:word;
begin
if x<2 then snt:=false
else
begin
snt:=true;
for i:=2 to trunc(sqrt(x)) do
if x mod i=0 then exit(false);
end;
end;
BEGIN
clrscr;
write('Nhap N:'); readln(n);
j:=1;
repeat
inc(j);
if snt(so(j)) then dec(n);
until
n=0;
write(j);
readln
END.
Chúc bạn học tốt!