Primality by Wilson's theorem: Difference between revisions
Content added Content deleted
(Added Easylang) |
Not a robot (talk | contribs) (Add Modula-2) |
||
Line 1,816: | Line 1,816: | ||
{{out}} |
{{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> |
<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|Modula-2}}== |
|||
<syntaxhighlight lang="modula2">MODULE WilsonPrimes; |
|||
FROM InOut IMPORT WriteCard, WriteLn; |
|||
VAR i: CARDINAL; |
|||
PROCEDURE Wilson(n: CARDINAL): BOOLEAN; |
|||
VAR |
|||
f, i: CARDINAL; |
|||
BEGIN |
|||
IF n<2 THEN RETURN FALSE END; |
|||
f := 1; |
|||
FOR i := n-1 TO 2 BY -1 DO |
|||
f := f*i MOD n |
|||
END; |
|||
RETURN f + 1 = n |
|||
END Wilson; |
|||
BEGIN |
|||
FOR i := 1 TO 100 DO |
|||
IF Wilson(i) THEN |
|||
WriteCard(i, 3) |
|||
END |
|||
END; |
|||
WriteLn |
|||
END WilsonPrimes.</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|Nim}}== |
=={{header|Nim}}== |