Sum multiples of 3 and 5: Difference between revisions
Content deleted Content added
Keithpinson (talk | contribs) m Removed "Insert formula here" added accidentally (I guess) when RunBasic Added |
|||
Line 308: | Line 308: | ||
=={{header|Mathematica}}== |
=={{header|Mathematica}}== |
||
<lang mathematica>sum35[n_] := |
|||
{{incorrect|Mathematica|Functions of n required instead of hard-coding 1000 and 1e20.}} |
|||
Sum[k, {k, 3, n - 1, 3}] + Sum[k, {k, 5, n - 1, 5}] - |
|||
<lang mathematica>Total[Select[Range[1000-1],Divisible[#,3]||Divisible[#,5]&]]</lang> |
|||
Sum[k, {k, 15, n - 1, 15}] |
|||
sum35[1000]</lang> |
|||
{{out}} |
{{out}} |
||
<pre>233168</pre> |
<pre>233168</pre> |
||
<lang mathematica> |
<lang mathematica>sum35[10^20]</lang> |
||
{{out}} |
{{out}} |
||
<pre>233333333333333333333166666666666666666668</pre> |
<pre>233333333333333333333166666666666666666668</pre> |