33 lines
731 B
Plaintext
33 lines
731 B
Plaintext
function isPrime(n)
|
|
if n < 2 then isPrime = 0 : goto [exit]
|
|
if n = 2 then isPrime = 1 : goto [exit]
|
|
if n mod 2 = 0 then isPrime = 0 : goto [exit]
|
|
isPrime = 1
|
|
for i = 3 to int(n^.5) step 2
|
|
if n mod i = 0 then isPrime = 0 : goto [exit]
|
|
next i
|
|
[exit]
|
|
end function
|
|
|
|
function factorial(n)
|
|
factorial = 1
|
|
if n > 1 then factorial = n * factorial(n -1)
|
|
end function
|
|
|
|
print "First 10 factorial primes:"
|
|
found = 0
|
|
i = 1
|
|
while found < 10
|
|
fct = factorial(i)
|
|
|
|
if isPrime(fct-1) then
|
|
found = found + 1
|
|
print using("##", found); ": "; using("##", i); "! - 1 = "; fct-1
|
|
end if
|
|
if isPrime(fct+1) then
|
|
found = found + 1
|
|
print using("##", found); ": "; using("##", i); "! + 1 = "; fct+1
|
|
end if
|
|
i = i + 1
|
|
wend
|