3 ms·
Solution 2 is still iterating, once by 3, then by 5 then by 15. Solution 3 uses the closed-form solutions the the question "what is the sum of the multiples of
by kadoban 5y ago
Solution 2 is still iterating, once by 3, then by 5 then by 15.
Solution 3 uses the closed-form solutions the the question "what is the sum of the multiples of k between x and y".
If you're not familiar with that last part, it's pretty easy to get there from the formula for the sum of numbers from 1 to n, ie n(n+1)/2 (which is itself ~easy to see by pairing up 1 and n, then 2 and (n-1) and etc.)