function sumOfMultiples(limit) {
// Calculate the upper bounds
const upperForThree = Math.floor(limit / 3);
const upperForFive = Math.floor(limit / 5);
const upperForFifteen = Math.floor(limit / 15);
// Calculate the sums using arithmetic series formula
const sumThree = 3 * upperForThree * (1 + upperForThree) / 2;
const sumFive = 5 * upperForFive * (1 + upperForFive) / 2;
const sumFifteen = 15 * upperForFifteen * (1 + upperForFifteen) / 2;
// Calculate the total sum
return sumThree + sumFive - sumFifteen;
}
// Define the limit
const limit = 999;
// Calculate and print the result
console.log(sumOfMultiples(limit));
/*
run:
233168
*/