Task

The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n.

Show output for n = 1000.

This is is the same as Project Euler problem 1.

Extra credit: do this efficiently for n = 1e20 or higher.




sumi(n, inc):= block(
  [kmax],
 
  /* below n means [1 .. n-1] */
  kmax: quotient(n-1, inc),
  return(
    ''(ev(sum(inc*k, k, 1, kmax), simpsum))
  )
);
 
sum35(n):= sumi(n, 3) + sumi(n, 5) - sumi(n, 15);
 
sum35(1000);
sum35(10^20);