Carmichael 3 strong pseudoprimes: Difference between revisions
Content added Content deleted
(added Chernick's Carmichael numbers as related task) |
(Add Factor) |
||
Line 626: | Line 626: | ||
61 x 241 x 421 = 6189121 |
61 x 241 x 421 = 6189121 |
||
61 x 3361 x 4021 = 824389441 |
61 x 3361 x 4021 = 824389441 |
||
</pre> |
|||
=={{header|Factor}}== |
|||
Note the use of <code>rem</code> instead of <code>mod</code> when the remainder should always be positive. |
|||
<lang factor>USING: formatting kernel locals math math.primes math.ranges |
|||
sequences ; |
|||
IN: rosetta-code.carmichael |
|||
:: carmichael ( p1 -- ) |
|||
1 p1 (a,b) [| h3 | |
|||
h3 p1 + [1,b) [| d | |
|||
h3 p1 + p1 1 - * d mod zero? |
|||
p1 neg p1 * h3 rem d h3 mod = and |
|||
[ |
|||
p1 1 - h3 p1 + * d /i 1 + :> p2 |
|||
p1 p2 * h3 /i 1 + :> p3 |
|||
p2 p3 [ prime? ] both? |
|||
p2 p3 * p1 1 - mod 1 = and |
|||
[ p1 p2 p3 "%d %d %d\n" printf ] when |
|||
] when |
|||
] each |
|||
] each |
|||
; |
|||
: carmichael-demo ( -- ) 61 primes-upto [ carmichael ] each ; |
|||
MAIN: carmichael-demo</lang> |
|||
{{out}} |
|||
<pre> |
|||
3 11 17 |
|||
5 29 73 |
|||
5 17 29 |
|||
5 13 17 |
|||
7 19 67 |
|||
7 31 73 |
|||
7 13 31 |
|||
7 23 41 |
|||
7 73 103 |
|||
7 13 19 |
|||
13 61 397 |
|||
13 37 241 |
|||
13 97 421 |
|||
13 37 97 |
|||
13 37 61 |
|||
17 41 233 |
|||
17 353 1201 |
|||
19 43 409 |
|||
19 199 271 |
|||
23 199 353 |
|||
29 113 1093 |
|||
29 197 953 |
|||
31 991 15361 |
|||
31 61 631 |
|||
31 151 1171 |
|||
31 61 271 |
|||
31 61 211 |
|||
31 271 601 |
|||
31 181 331 |
|||
37 109 2017 |
|||
37 73 541 |
|||
37 613 1621 |
|||
37 73 181 |
|||
37 73 109 |
|||
41 1721 35281 |
|||
41 881 12041 |
|||
41 101 461 |
|||
41 241 761 |
|||
41 241 521 |
|||
41 73 137 |
|||
41 61 101 |
|||
43 631 13567 |
|||
43 271 5827 |
|||
43 127 2731 |
|||
43 127 1093 |
|||
43 211 757 |
|||
43 631 1597 |
|||
43 127 211 |
|||
43 211 337 |
|||
43 433 643 |
|||
43 547 673 |
|||
43 3361 3907 |
|||
47 3359 6073 |
|||
47 1151 1933 |
|||
47 3727 5153 |
|||
53 157 2081 |
|||
53 79 599 |
|||
53 157 521 |
|||
59 1451 2089 |
|||
61 421 12841 |
|||
61 181 5521 |
|||
61 1301 19841 |
|||
61 277 2113 |
|||
61 181 1381 |
|||
61 541 3001 |
|||
61 661 2521 |
|||
61 271 571 |
|||
61 241 421 |
|||
61 3361 4021 |
|||
</pre> |
</pre> |
||