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.




procedure main(A)
    n := (integer(A[1]) | 1000)-1
    write(sum(n,3)+sum(n,5)-sum(n,15))
end
 
procedure sum(n,m)
    return m*((n/m)*(n/m+1)/2)
end