Skip to content

Commit 70c0e59

Browse files
authored
Merge pull request SjxSubham#131 from RajanyaSaha-27/main
2894. Divisible and Non-divisible Sums Difference.cpp
2 parents 5add706 + 36296b6 commit 70c0e59

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
int differenceOfSums(int n, int m) {
4+
int num1 = 0, num2 = 0;
5+
for (int i = 1; i <= n; i++) {
6+
if (i % m == 0)
7+
num2 += i; // divisible by m
8+
else
9+
num1 += i; // not divisible by m
10+
}
11+
return num1 - num2;
12+
}
13+
};

0 commit comments

Comments
 (0)