You are viewing a single comment's thread. Return to all comments →
Optimise solution to reduce O(n) to O(1).
sum of multiple of x = x * k * (k + 1) / 2 where, k = n - 1 / x
use this mathematical formula to sum of multiples. Instead of iterating through all numbers less than n
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #1: Multiples of 3 and 5
You are viewing a single comment's thread. Return to all comments →
Optimise solution to reduce O(n) to O(1).
sum of multiple of x = x * k * (k + 1) / 2 where, k = n - 1 / x
use this mathematical formula to sum of multiples. Instead of iterating through all numbers less than n