JuniorMath
Divisible and Non-divisible Sums Difference
You are given positive integers n and m.
Define two integers as follows:
num1: The sum of all integers in the range[1, n](both inclusive) that are not divisible bym.num2: The sum of all integers in the range[1, n](both inclusive) that are divisible bym.
Return the integer num1 - num2.
Example 1
Input
n = 10, m = 3Output
19Integers not divisible by 3 sum to 37, integers divisible by 3 sum to 18, so the answer is 37 - 18 = 19.
Example 2
Input
n = 5, m = 6Output
15All integers from 1 to 5 are not divisible by 6, so num1 is 15 and num2 is 0.
Constraints
- 1 <= n, m <= 1000