uses crt;
function Prost(n:longint):boolean;
var i:longint;
begin
if n<2 then Prost:=false
else
begin
Prost:=true;
for i:=2 to round(sqrt(n)) do
if n mod i=0 then
begin
Prost:=false;
break;
end;
end;
end;
var k,p,q:integer;
i:longint;
begin
clrscr;
repeat
write('Введите число от 1 до 500 k=');
readln(k);
until(k>=1)and(k<=500);
i:=0;p:=0;q:=0;
while q<k do
begin
i:=i+1;
if Prost(i)then p:=p+1;
if Prost(p) and Prost(i) then q:=q+1;
end;
write('p=',p,' q=',q,' Pk=',i);
readln
end.