Maybe like this:
function sumMul(n, m) { if (m <= n) return "INVALID"; const l = m - (m % n || n); return (n + l) / 2 * l / n; }
This is based on the fact that the average of [2, 8] is the same as the average of [2, 4, 6, 8], which means that (2 + 8) / 2 === (2 + 4 + 6 + 8) / 4, where 2 + 4 + 6 + 8 is the sum you're looking for.
[2, 8]
[2, 4, 6, 8]
(2 + 8) / 2 === (2 + 4 + 6 + 8) / 4
2 + 4 + 6 + 8
Good luck!
Great solution bro, I just tested it and it works 🔥
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Maybe like this:
This is based on the fact that the average of
[2, 8]
is the same as the average of[2, 4, 6, 8]
, which means that(2 + 8) / 2 === (2 + 4 + 6 + 8) / 4
, where2 + 4 + 6 + 8
is the sum you're looking for.Good luck!
Great solution bro, I just tested it and it works 🔥