Erdös-Selfridge categorization of primes: Difference between revisions
Content added Content deleted
(Added Sidef) |
|||
Line 538: | Line 538: | ||
Category 11 => first: 8524807, total: 1, last:8524807 |
Category 11 => first: 8524807, total: 1, last:8524807 |
||
</pre> |
</pre> |
||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
|||
<lang Mathematica>ClearAll[SpecialPrimeFactors] |
|||
SpecialPrimeFactors[p_Integer] := FactorInteger[p + 1][[All, 1]] |
|||
ps = Prime[Range[200]]; |
|||
cs = {{2, 3}}; |
|||
Do[ |
|||
If[Length[ps] > 0, |
|||
newc = |
|||
Select[ps, |
|||
Complement[SpecialPrimeFactors[#], Catenate[cs]] === {} &]; |
|||
AppendTo[cs, newc]; |
|||
ps = Complement[ps, newc]; |
|||
, |
|||
Break[] |
|||
] |
|||
, |
|||
{n, 1, \[Infinity]} |
|||
]; |
|||
Do[ |
|||
Print["Category: ", i - 1]; |
|||
Print@Multicolumn[cs[[i]], {Automatic, 10}] |
|||
, |
|||
{i, Length[cs]} |
|||
] |
|||
ps = Prime[Range[1000000]]; |
|||
ps = Parallelize[{#, SpecialPrimeFactors[#]} & /@ ps]; |
|||
cs = {{2, 3}}; |
|||
Do[ |
|||
If[Length[ps] > 0, |
|||
newcs = Last[cs]; |
|||
ps[[All, 2]] = ps[[All, 2]] /. Dispatch[Thread[newcs -> Nothing]]; |
|||
newc = Select[ps, Last/*Length/*EqualTo[0]]; |
|||
ps = Complement[ps, newc]; |
|||
newc = newc[[All, 1]]; |
|||
AppendTo[cs, newc]; |
|||
, |
|||
Break[] |
|||
] |
|||
, |
|||
{n, 1, \[Infinity]} |
|||
]; |
|||
TableForm[{First[#], Last[#], Length[#]} & /@ Rest[cs], |
|||
TableHeadings -> {Automatic, {"First", "Last", "Count"}}, |
|||
TableAlignments -> Right]</lang> |
|||
{{out}} |
|||
<pre> |
|||
Category: 0 |
|||
2 3 |
|||
Category: 1 |
|||
2 5 11 23 47 71 127 383 647 971 |
|||
3 7 17 31 53 107 191 431 863 1151 |
|||
Category: 2 |
|||
13 83 167 251 349 479 599 761 967 1223 |
|||
19 89 179 263 359 499 619 769 991 |
|||
29 97 197 269 367 503 641 809 1019 |
|||
41 101 199 271 373 509 643 827 1033 |
|||
43 109 211 281 419 557 659 839 1049 |
|||
59 131 223 283 433 563 709 881 1069 |
|||
61 137 229 293 439 577 719 919 1087 |
|||
67 139 239 307 449 587 743 929 1103 |
|||
79 149 241 317 461 593 751 953 1187 |
|||
Category: 3 |
|||
37 193 347 457 547 683 821 937 1051 1163 |
|||
103 227 353 463 569 701 829 947 1061 1171 |
|||
113 233 379 467 571 727 853 983 1063 1181 |
|||
151 257 389 487 601 733 857 997 1091 1193 |
|||
157 277 397 491 607 773 859 1009 1097 1217 |
|||
163 311 401 521 613 787 877 1013 1117 |
|||
173 331 409 523 631 797 883 1031 1123 |
|||
181 337 421 541 653 811 911 1039 1153 |
|||
Category: 4 |
|||
73 443 661 677 739 823 907 977 1109 1201 |
|||
313 617 673 691 757 887 941 1093 1129 1213 |
|||
Category: 5 |
|||
1021 |
|||
First Last Count |
|||
1 2 10616831 46 |
|||
2 13 15482669 10497 |
|||
3 37 15485863 201987 |
|||
4 73 15485849 413891 |
|||
5 1021 15485837 263109 |
|||
6 2917 15485857 87560 |
|||
7 15013 15484631 19389 |
|||
8 49681 15485621 3129 |
|||
9 532801 15472811 363 |
|||
10 1065601 15472321 28 |
|||
11 8524807 8524807 1</pre> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |