object SumOfMultiples {
def main(args: Array[String]): Unit = {
val limit = 999
// Calculate the upper bounds
val upperForThree = limit / 3
val upperForFive = limit / 5
val upperForFifteen = limit / 15
// Calculate the sums using the arithmetic series formula
val sumThree = 3 * upperForThree * (1 + upperForThree) / 2
val sumFive = 5 * upperForFive * (1 + upperForFive) / 2
val sumFifteen = 15 * upperForFifteen * (1 + upperForFifteen) / 2
// Calculate the total sum
val totalSum = sumThree + sumFive - sumFifteen
println(totalSum)
}
}
/*
run:
233168
*/