Primality by Wilson's theorem: Difference between revisions

Added Lua
m (typo)
(Added Lua)
Line 999:
 
The first 40 Wilson primes above 7900 are: [7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, 8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209, 8219, 8221, 8231, 8233, 8237, 8243, 8263, 8269]
</pre>
 
=={{header|Lua}}==
<lang lua>-- primality by Wilson's theorem
 
function isWilsonPrime( n )
local fmodp = 1
for i = 1, n - 1 do
fmodp = fmodp * i
fmodp = fmodp % n
end
return (fmodp + 1 ) % n == 0
end
 
for n = 2, 100 do
if isWilsonPrime( n ) then
io.write( " " .. n )
end
end</lang>
{{out}}
<pre>
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
</pre>
 
3,043

edits