2894: Divisible-and-Non-divisible-Sums-Difference
Easy


table of contents

Lowkey, just follow what the question tells you to do.

code

class Solution {
public:
    int differenceOfSums(int n, int m) {
        int divisible = 0, notDivisible = 0;
        for (int i = 1; i <= n; ++i) {
            if ((i % m) != 0) {
                notDivisible += i;
            } else {
                divisible += i;
            }
        }
        return notDivisible - divisible;
    }
};

complexity

time taken