Pairs with common factors: Difference between revisions
Content added Content deleted
(→{{header|RPL}}: HP-49+ version) |
(Add Mathematica/Wolfram Language implementation) |
||
Line 652: | Line 652: | ||
669 700 726 757 773 818 818 853 877 922 922 969 969 1006 1040 1079 1095 1148 1148 1195 |
669 700 726 757 773 818 818 853 877 922 922 969 969 1006 1040 1079 1095 1148 1148 1195 |
||
1221 1262 1262 1321 1341 1384 1414 1461 1461 1526 1544 1591 1623 1670 1692 1755 1755 1810 1848 1907 |
1221 1262 1262 1321 1341 1384 1414 1461 1461 1526 1544 1591 1623 1670 1692 1755 1755 1810 1848 1907 |
||
The 10th pair with common factors count is 14 |
|||
The 100th pair with common factors count is 1,907 |
|||
The 1,000th pair with common factors count is 195,309 |
|||
The 10,000th pair with common factors count is 19,597,515 |
|||
The 100,000th pair with common factors count is 1,960,299,247 |
|||
The 1,000,000th pair with common factors count is 196,035,947,609 |
|||
</pre> |
|||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
|||
{{trans|Julia}} |
|||
<syntaxhighlight lang="mathematica">(* Define the prime counting function (pcf) *) |
|||
pcf[n_] := n (n - 1)/2 + 1 - Total[EulerPhi /@ Range[n]] |
|||
(* Print pairs of (n, pcf(n)) for n from 1 to 100 *) |
|||
Do[ |
|||
Module[{pair = pcf[n], pairString}, |
|||
pairString = ToString[StringPadRight[ToString[pair], 5]]; |
|||
If[Mod[n, 20] == 0, |
|||
WriteString["stdout", pairString <> "\n"], |
|||
WriteString["stdout", pairString, " "] |
|||
] |
|||
], |
|||
{n, 1, 100} |
|||
] |
|||
(* Print the 10^expo-th pair with common factors count *) |
|||
Do[ |
|||
Print["The ", ToString[NumberForm[10^expo, DigitBlock -> 3]], |
|||
"th pair with common factors count is ", |
|||
ToString[NumberForm[pcf[10^expo], DigitBlock -> 3]]], |
|||
{expo, 1, 6} |
|||
]</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
0 0 0 1 1 4 4 7 9 14 14 21 21 28 34 41 41 52 52 63 |
|||
71 82 82 97 101 114 122 137 137 158 158 173 185 202 212 235 235 254 268 291 |
|||
291 320 320 343 363 386 386 417 423 452 470 497 497 532 546 577 597 626 626 669 |
|||
669 700 726 757 773 818 818 853 877 922 922 969 969 1006 1040 1079 1095 1148 1148 1195 |
|||
1221 1262 1262 1321 1341 1384 1414 1461 1461 1526 1544 1591 1623 1670 1692 1755 1755 1810 1848 1907 |
|||
The 10th pair with common factors count is 14 |
The 10th pair with common factors count is 14 |
||
The 100th pair with common factors count is 1,907 |
The 100th pair with common factors count is 1,907 |