You are viewing a single comment's thread. Return to all comments →
KOTLIN Code
private fun calculateMultipleSums(n: Int){ /* 100/3 = 33 100/5 = 20 100/15 = 6 (n*(n+1))/2 */ val sumOfThree = 3* findSum(findMultiplier(n, 3)) val sumOfFive = 5* findSum(findMultiplier(n, 5)) val sumOfFifteen = 15* findSum(findMultiplier(n, 15)) println( sumOfThree +sumOfFive - sumOfFifteen) } private fun findSum(n: Long): Long{ return (n * (n+1))/2 } private fun findMultiplier(n: Int, m: Long): Long{ return ((n-1)/m) }
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 →
KOTLIN Code