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.




threeor5: procedure options (main);      /* 8 June 2014 */
   declare (i, n) fixed(10), sum fixed (31) static initial (0);
 
   get (n);
   put ('The number of multiples of 3 or 5 below ' || trim(n) || ' is');
 
   do i = 1 to n-1;
      if mod(i, 3) = 0 | mod(i, 5) = 0 then sum = sum + i;
   end;
 
   put edit ( trim(sum) ) (A);
 
end threeor5;