Jump to content

Pairs with common factors: Difference between revisions

→‎{{header|Raku}}: well duh, don't have to reify ''all'' of the terms that aren't being displayed.
(Added Wren)
(→‎{{header|Raku}}: well duh, don't have to reify ''all'' of the terms that aren't being displayed.)
Line 55:
my \𝜑 = 0, |(1..*).hyper.map: -> \t { t × [×] t.&prime-factors.unique.map: { 1 - 1/$_ } }
 
mysub @pairspair-with-common-factors =count (1..*).map: -> \n) { n × (n - 1) / 2 + 1 - sum (1..n).map: { 𝜑[$_] } }
 
my @pairs-with-common-factors = (1..*).map: &pair-count;
 
say "Number of pairs with common factors - first one hundred terms:\n"
~ @pairs-with-common-factors[^100].batch(10)».&comma».fmt("%6s").join("\n") ~ "\n";
 
for ^57 { say (my $i = 10 ** $_).&ordinal.tc.fmt("%15s22s term: ") ~ @pairs-with-common-factors[$i .&pair- 1]count.&comma }</lang>
{{out}}
<pre>Number of pairs with common factors - first one hundred terms:
Line 74 ⟶ 76:
1,544 1,591 1,623 1,670 1,692 1,755 1,755 1,810 1,848 1,907
 
First term: 0
Tenth term: 14
One hundredth term: 1,907
One thousandth term: 195,309
Ten thousandth term: 19,597,515</pre>
One hundred thousandth term: 1,960,299,247
One millionth term: 196,035,947,609</pre>
 
=={{header|Wren}}==
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.