Primality by Wilson's theorem: Difference between revisions

Added PL/I
(Added Lua)
(Added PL/I)
Line 1,154:
<pre>
1 2 3 5 7 11
</pre>
 
=={{header|PL/I}}==
<lang pli>/* primality by Wilson's theorem */
wilson: procedure options( main );
declare n binary(15)fixed;
 
isWilsonPrime: procedure( n )returns( bit(1) );
declare n binary(15)fixed;
declare ( fmodp, i ) binary(15)fixed;
fmodp = 1;
do i = 1 to n - 1;
fmodp = mod( fmodp * i, n );
end;
return ( mod( fmodp + 1, n ) = 0 );
end isWilsonPrime ;
do n = 2 to 100;
if isWilsonPrime( n ) then do;
put edit( n ) ( f(3) );
end;
end;
end wilson ;</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,022

edits