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.




' FB 1.05.0 Win64
 
Function sum35 (n As UInteger) As UInteger
  If n = 0 Then Return 0
  Dim As UInteger i, sum = 0
  For i = 1 To n
    If (i Mod 3 = 0) OrElse (i Mod 5 = 0) Then sum += i
  Next
  Return sum 
End Function
 
Print "Sum of positive integers below 1000 divisible by 3 or 5 is : "; sum35(999)
Print
Print "Press any key to quit"
Sleep