Primality by Wilson's theorem: Difference between revisions

→‎{{header|Ring}}: Alternative version that can go beyond 19 Wilson primes
(→‎{{header|Ring}}: Alternative version that can go beyond 19 Wilson primes)
Line 1,521:
Is 18 prime: 0
Is 19 prime: 1
</pre>
 
Alternative version computing the factorials modulo n so as to avoid overflow.
<lang ring># primality by Wilson's theorem
 
limit = 100
 
for n = 1 to limit
if isWilsonPrime( n )
see " " + n
ok
next n
 
func isWilsonPrime n
fmodp = 1
for i = 2 to n - 1
fmodp *= i
fmodp %= n
next i
return fmodp = n - 1</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,038

edits