Sum multiples of 3 and 5: Difference between revisions

Line 1,306:
</pre>
 
=={{header|Frink}}==
Program has a brute-force approach for n=1000, and also inclusion/exclusion for larger values.
<lang Frink>
sum999 = sum[select[1 to 999, {|n| n mod 3 == 0 or n mod 5 == 0}]]
 
sumdiv[n, d] :=
{
m = floor[n/d]
m(m + 1)/2 d
}
 
sum35big[n] := sumdiv[n, 3] + sumdiv[n, 5] - sumdiv[n, 15]
 
println["The sum of all the multiples of 3 or 5 below 1000 is $sum999"]
println["The sum of all multiples less than 1e20 is " + sum35big[1_00000_00000_00000_00000 - 1]]
</lang>
{{Out}}
<pre>
The sum of all the multiples of 3 or 5 below 1000 is 233168
The sum of all multiples less than 1e20 is 2333333333333333333316666666666666666668
</pre>
=={{header|Go}}==
<lang go>package main
357

edits