Builds two arrays, indexed by “known to be prime and in the range of interest”, and “known to be not prime”.
on mouseUp
local tInput
put fld "FieldIn" into tInput
if the number of words in tInput <> 2 or \
word 1 of tInput is not a number or \
word 2 of tInput is not a number then
ask "must give 2 numbers"
exit mouseUp
end if
local tAPrime, tANonPrime
repeat with i = 2 to word 2 of tInput
if tANonPrime[i] then next repeat
if i >= word 1 of tInput then put true into tAPrime[i]
repeat with j = i+i to word 2 of tInput step i
put true into tANonPrime[j]
end repeat
end repeat
local tt
put "The number of primes between" && tInput && "is" && the number of lines in the keys of tAPrime & CR into fld "F"
put the keys of tAPrime into tt
sort lines of tt numeric
put "and they are" & CR & tt after fld "F"
end mouseUp