Carmichael 3 strong pseudoprimes: Difference between revisions
Content added Content deleted
(→{{header|Julia}}: A new entry for Julia) |
(→{{header|Ruby}}: Rubyfy) |
||
Line 1,146: | Line 1,146: | ||
{{works with|Ruby|1.9}} |
{{works with|Ruby|1.9}} |
||
<lang ruby># Generate Charmichael Numbers |
<lang ruby># Generate Charmichael Numbers |
||
# |
|||
# Nigel_Galloway |
|||
# November 30th., 2012. |
|||
# |
|||
require 'prime' |
require 'prime' |
||
Prime.each(61) do |p| |
|||
(2...p).each |
(2...p).each do |h3| |
||
g = h3 + p |
g = h3 + p |
||
(1...g).each |
(1...g).each do |d| |
||
next if (g*(p-1)) % d != 0 or (- |
next if (g*(p-1)) % d != 0 or (-p*p) % h3 != d % h3 |
||
q = 1 + ((p - 1) * g / d) |
q = 1 + ((p - 1) * g / d) |
||
next |
next unless q.prime? |
||
r = 1 + (p * q / h3) |
r = 1 + (p * q / h3) |
||
next |
next unless r.prime? and (q * r) % (p - 1) == 1 |
||
puts "#{p} |
puts "#{p} x #{q} x #{r}" |
||
end |
|||
end |
|||
puts |
puts |
||
end</lang> |
|||
{{out}} |
{{out}} |
||
<pre style="height:30ex;overflow:scroll"> |
<pre style="height:30ex;overflow:scroll"> |
||
3 |
3 x 11 x 17 |
||
5 |
5 x 29 x 73 |
||
5 |
5 x 17 x 29 |
||
5 |
5 x 13 x 17 |
||
7 |
7 x 19 x 67 |
||
7 |
7 x 31 x 73 |
||
7 |
7 x 13 x 31 |
||
7 |
7 x 23 x 41 |
||
7 |
7 x 73 x 103 |
||
7 |
7 x 13 x 19 |
||
13 |
13 x 61 x 397 |
||
13 |
13 x 37 x 241 |
||
13 |
13 x 97 x 421 |
||
13 |
13 x 37 x 97 |
||
13 |
13 x 37 x 61 |
||
17 |
17 x 41 x 233 |
||
17 |
17 x 353 x 1201 |
||
19 |
19 x 43 x 409 |
||
19 |
19 x 199 x 271 |
||
23 |
23 x 199 x 353 |
||
29 |
29 x 113 x 1093 |
||
29 |
29 x 197 x 953 |
||
31 |
31 x 991 x 15361 |
||
31 |
31 x 61 x 631 |
||
31 |
31 x 151 x 1171 |
||
31 |
31 x 61 x 271 |
||
31 |
31 x 61 x 211 |
||
31 |
31 x 271 x 601 |
||
31 |
31 x 181 x 331 |
||
37 |
37 x 109 x 2017 |
||
37 |
37 x 73 x 541 |
||
37 |
37 x 613 x 1621 |
||
37 |
37 x 73 x 181 |
||
37 |
37 x 73 x 109 |
||
41 |
41 x 1721 x 35281 |
||
41 |
41 x 881 x 12041 |
||
41 |
41 x 101 x 461 |
||
41 |
41 x 241 x 761 |
||
41 |
41 x 241 x 521 |
||
41 |
41 x 73 x 137 |
||
41 |
41 x 61 x 101 |
||
43 |
43 x 631 x 13567 |
||
43 |
43 x 271 x 5827 |
||
43 |
43 x 127 x 2731 |
||
43 |
43 x 127 x 1093 |
||
43 |
43 x 211 x 757 |
||
43 |
43 x 631 x 1597 |
||
43 |
43 x 127 x 211 |
||
43 |
43 x 211 x 337 |
||
43 |
43 x 433 x 643 |
||
43 |
43 x 547 x 673 |
||
43 |
43 x 3361 x 3907 |
||
47 |
47 x 3359 x 6073 |
||
47 |
47 x 1151 x 1933 |
||
47 |
47 x 3727 x 5153 |
||
53 |
53 x 157 x 2081 |
||
53 |
53 x 79 x 599 |
||
53 |
53 x 157 x 521 |
||
59 |
59 x 1451 x 2089 |
||
61 |
61 x 421 x 12841 |
||
61 |
61 x 181 x 5521 |
||
61 |
61 x 1301 x 19841 |
||
61 |
61 x 277 x 2113 |
||
61 |
61 x 181 x 1381 |
||
61 |
61 x 541 x 3001 |
||
61 |
61 x 661 x 2521 |
||
61 |
61 x 271 x 571 |
||
61 |
61 x 241 x 421 |
||
61 |
61 x 3361 x 4021 |
||
</pre> |
</pre> |
||