RosettaCodeData/Task/Primality-by-Wilsons-theorem/FreeBASIC/primality-by-wilsons-theorem.basic

14 lines
387 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
function wilson_prime( n as uinteger ) as boolean
dim as uinteger fct=1, i
for i = 2 to n-1
'because (a mod n)*b = (ab mod n)
'it is not necessary to calculate the entire factorial
fct = (fct * i) mod n
next i
if fct = n-1 then return true else return false
end function
for i as uinteger = 2 to 100
if wilson_prime(i) then print i,
next i