Skip to content

Commit dc080df

Browse files
authored
Create 2894. Divisible and Non-divisible Sums Difference (#806)
2 parents 55f3426 + db502fb commit dc080df

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public:
3+
int differenceOfSums(int n, int m) {
4+
// we need to find S(n)-2*(divisibles)
5+
6+
// no of divisibles
7+
int x=n/m;
8+
9+
return (n*(n+1))/2-2*m*((x*(x+1))/2);
10+
}
11+
};

0 commit comments

Comments
 (0)