Problem List

Divisible And Non Divisible Sums Difference

May 26, 2025Go math

Go Solution
func differenceOfSums(n int, m int) int {
  res:= 0
  for i := 1; i <= n; i++ {
    if i % m != 0 {
      res += i
    } else {
      res -= i
    }
  }

  return res
}
LeetCode Problem Link