uses crt;
var i,n,j,dem:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
dem:=0;
for j:=1 to i do
if i mod j=0 then inc(dem);
if dem=3 then write(i:4);
end;
readln;
end.
var n,i,dem:longint;
function cp(so:longint):boolean;
begin
if sqr(trunc(sqrt(so)))=so then exit(true)
else exit(false);
end;
function nt(so:longint):boolean;
var k:longint;
begin
if (so=2) or (so=3) then exit(true);
if (so=1) or (so mod 2=0) or (so mod 3=0) then exit(false);
k:=5;
repeat
if (so mod k =0) or (so mod (k+2)=0) then break;
inc(k,6);
until k>trunc(sqrt(so));
exit(k>trunc(sqrt(so)));
end;
begin
write('nhap n:');readln(n);
dem:=0;
for i:=1 to n do
begin
if (cp(i)) and (nt(trunc(sqrt(i)))) then
begin writeln(i); inc(dem); end;
end;
write(dem);
readln;
end.
code này chạy khoảng 9s nhé! còn cách tối ưu hơn mong mọi người chỉ bảo!
Program hotrotinhoc;
var d,i,n: longint;
function nt(x:longint): boolean;
var i: integer;
begin
nt:=true;
if (x=2) or (x=3) then exit;
nt:=false;
if (x mod 2=0) or (x mod 3=0) or (x=1) then exit;
i:=5;
while i<=trunc(sqrt(x)) do
begin
if (x mod i=0) or (x mod (i+2)=0) then exit;
i:=i+6;
end;
nt:=true;
end;
begin
readln(n);
d:=0;
for i:=1 to trunc(sqrt(n)) do
if nt(i) then inc(d);
write(d);
readln;
end.
uses crt;
var i,n,j,dem:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
dem:=0;
for j:=1 to i do
if i mod j=0 then inc(dem);
if dem=3 then write(i:4);
end;
readln;
end.