Pairs with common factors: Difference between revisions

Content added Content deleted
(→‎{{header|J}}: add some quick documentation)
Line 101: Line 101:


Here, <code>p.</code> calculates a polynomial (1 + (-x)/2 + (x^2)/2 in this example), <code>5&p:</code> is euler's totient function, <code>@{:</code> modifies the polynomial to only operate on the final element of a sequence, <code>+/</code> is sum and <code>+/\</code> is running sum, and <code>1+i.n</code> is the sequence of numbers 1 through n.
Here, <code>p.</code> calculates a polynomial (1 + (-x)/2 + (x^2)/2 in this example), <code>5&p:</code> is euler's totient function, <code>@{:</code> modifies the polynomial to only operate on the final element of a sequence, <code>+/</code> is sum and <code>+/\</code> is running sum, and <code>1+i.n</code> is the sequence of numbers 1 through n.

=={{header|Julia}}==
<lang ruby>using Formatting
using Primes

pcf(n) = n * (n - 1) ÷ 2 + 1 - sum(totient, 1:n)

foreach(p -> print(rpad(p[2], 5), p[1] % 20 == 0 ? "\n" : ""), pairs(map(pcf, 1:100)))

for expo in 0:6
println("The ", format(10^expo, commas = true), "th pair with common factors count is ",
format(pcf(10^expo), commas = true))
end
</lang{{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 1th pair with common factors count is 0
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|Phix}}==
=={{header|Phix}}==