Primality by Wilson's theorem: Difference between revisions

Added XPL0 example.
(Added PROMAL)
(Added XPL0 example.)
Line 2,322:
19 -> prime
</pre>
 
=={{header|XPL0}}==
{{trans|ALGOL W}}
<syntaxhighlight lang "XPL0"> \ find primes using Wilson's theorem:
\ p is prime if ( ( p - 1 )! + 1 ) mod p = 0
 
\ returns true if N is a prime by Wilson's theorem, false otherwise
\ computes the factorial mod p at each stage, so as to
\ allow numbers whose factorial won't fit in 32 bits
function IsWilsonPrime; integer N ;
integer FactorialModN, I;
begin
FactorialModN := 1;
for I := 2 to N - 1 do FactorialModN := rem( FactorialModN * I / N );
return FactorialModN = N - 1
end \isWilsonPrime\ ;
 
integer I;
for I := 1 to 100 do if IsWilsonPrime( I ) then [IntOut(0, I); ChOut(0, ^ )]</syntaxhighlight>
{{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>
 
=={{header|zkl}}==
291

edits