Equal prime and composite sums: Difference between revisions
Content added Content deleted
m (→{{header|Sidef}}: less code) |
|||
Line 362: | Line 362: | ||
44.526876 seconds (1.09 G allocations: 16.546 GiB, 3.13% gc time) |
44.526876 seconds (1.09 G allocations: 16.546 GiB, 3.13% gc time) |
||
</pre> |
</pre> |
||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
|||
<lang Mathematica>$HistoryLength = 1; |
|||
ub = 10^8; |
|||
ps = Prime[Range[PrimePi[ub]]]; |
|||
cs = Complement[Range[2, ub], ps]; |
|||
cps = Accumulate[ps]; |
|||
ccs = Accumulate[cs]; |
|||
indices = Intersection[cps, ccs]; |
|||
poss = {FirstPosition[cps, #], FirstPosition[ccs, #]} & /@ indices; |
|||
TableForm[MapThread[Prepend, {Flatten /@ poss, indices}], |
|||
TableHeadings -> {None, {"Sum", "Prime Index", "Composite Index"}}, |
|||
TableAlignments -> Right]</lang> |
|||
{{out}} |
|||
<pre>Sum Prime Index Composite Index |
|||
10 3 2 |
|||
1988 33 51 |
|||
14697 80 147 |
|||
83292 175 361 |
|||
1503397 660 1582 |
|||
18859052 2143 5699 |
|||
93952013 4556 12821 |
|||
89171409882 118785 403341 |
|||
9646383703961 1131142 4229425 |
|||
209456854921713 5012372 19786181</pre> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |