2894. Divisible and Non-divisible Sums Difference

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2894

class Solution:
    def differenceOfSums(self, n: int, m: int) -> int:
        return sum(i if i % m else -i for i in range(1, n + 1))