Primality by Wilson's theorem: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(Added Action!) |
||
Line 133: | Line 133: | ||
241 |
241 |
||
251 |
251 |
||
</pre> |
|||
=={{header|Action!}}== |
|||
{{Trans|PL/M}} |
|||
<syntaxhighlight lang="action!"> |
|||
;;; returns TRUE(1) if p is prime by Wilson's theorem, FALSE(0) otherwise |
|||
;;; computes the factorial mod p at each stage, so as to allow |
|||
;;; for numbers whose factorial won't fit in 16 bits |
|||
BYTE FUNC isWilsonPrime( CARD p ) |
|||
CARD i, factorial_mod_p |
|||
BYTE result |
|||
factorial_mod_p = 1 |
|||
FOR i = 2 TO p - 1 DO |
|||
factorial_mod_p = ( factorial_mod_p * i ) MOD p |
|||
OD |
|||
IF factorial_mod_p = p - 1 THEN result = 1 ELSE result = 0 FI |
|||
RETURN( result ) |
|||
PROC Main() |
|||
CARD i |
|||
FOR i = 1 TO 100 DO |
|||
IF isWilsonPrime( i ) THEN |
|||
Put(' ) PrintC( i ) |
|||
FI |
|||
OD |
|||
RETURN |
|||
</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> |
</pre> |
||