Hey why i am seeing time limit exceed in codechef but however on codechef’s code compile and run its perfectly working and it says time taken to be 0 seconds as i am an spoj user too so i submitted there also and it worked correctly giving just time taken to be 1.89 seconds code is here…
program PRIME1;
uses Math;
var
<var>
T:integer;
N,M:longint;
i,y,pos:longint;
</var>
begin
read(T);
while T <> 0 do
begin
readln(M,N);
for i := M to N do
begin
pos := ceil(sqrt(i));
for y := 2 to pos do
begin
if i mod y = 0 then break
else continue;
end;
if i > 1 then
begin
if (i mod y <> 0) or (i=2)then
writeln(i);
end;
end;
writeln;
T := T-1;
end;
end.
as i suppose there is not any better approach that the sqrt(num) for finding wheter it is prime or not or there any then please do tell?