|
| 1 | +<p>You are given positive integers <code>n</code> and <code>m</code>.</p> |
| 2 | + |
| 3 | +<p>Define two integers as follows:</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <li><code>num1</code>: The sum of all integers in the range <code>[1, n]</code> (both <strong>inclusive</strong>) that are <strong>not divisible</strong> by <code>m</code>.</li> |
| 7 | + <li><code>num2</code>: The sum of all integers in the range <code>[1, n]</code> (both <strong>inclusive</strong>) that are <strong>divisible</strong> by <code>m</code>.</li> |
| 8 | +</ul> |
| 9 | + |
| 10 | +<p>Return <em>the integer</em> <code>num1 - num2</code>.</p> |
| 11 | + |
| 12 | +<p> </p> |
| 13 | +<p><strong class="example">Example 1:</strong></p> |
| 14 | + |
| 15 | +<pre> |
| 16 | +<strong>Input:</strong> n = 10, m = 3 |
| 17 | +<strong>Output:</strong> 19 |
| 18 | +<strong>Explanation:</strong> In the given example: |
| 19 | +- Integers in the range [1, 10] that are not divisible by 3 are [1,2,4,5,7,8,10], num1 is the sum of those integers = 37. |
| 20 | +- Integers in the range [1, 10] that are divisible by 3 are [3,6,9], num2 is the sum of those integers = 18. |
| 21 | +We return 37 - 18 = 19 as the answer. |
| 22 | +</pre> |
| 23 | + |
| 24 | +<p><strong class="example">Example 2:</strong></p> |
| 25 | + |
| 26 | +<pre> |
| 27 | +<strong>Input:</strong> n = 5, m = 6 |
| 28 | +<strong>Output:</strong> 15 |
| 29 | +<strong>Explanation:</strong> In the given example: |
| 30 | +- Integers in the range [1, 5] that are not divisible by 6 are [1,2,3,4,5], num1 is the sum of those integers = 15. |
| 31 | +- Integers in the range [1, 5] that are divisible by 6 are [], num2 is the sum of those integers = 0. |
| 32 | +We return 15 - 0 = 15 as the answer. |
| 33 | +</pre> |
| 34 | + |
| 35 | +<p><strong class="example">Example 3:</strong></p> |
| 36 | + |
| 37 | +<pre> |
| 38 | +<strong>Input:</strong> n = 5, m = 1 |
| 39 | +<strong>Output:</strong> -15 |
| 40 | +<strong>Explanation:</strong> In the given example: |
| 41 | +- Integers in the range [1, 5] that are not divisible by 1 are [], num1 is the sum of those integers = 0. |
| 42 | +- Integers in the range [1, 5] that are divisible by 1 are [1,2,3,4,5], num2 is the sum of those integers = 15. |
| 43 | +We return 0 - 15 = -15 as the answer. |
| 44 | +</pre> |
| 45 | + |
| 46 | +<p> </p> |
| 47 | +<p><strong>Constraints:</strong></p> |
| 48 | + |
| 49 | +<ul> |
| 50 | + <li><code>1 <= n, m <= 1000</code></li> |
| 51 | +</ul> |
0 commit comments