2894. Divisible and Non-divisible Sums Difference Easy

@problem@discussion
#Math



1/**
2 * [2894] Divisible and Non-divisible Sums Difference
3 *
4 * You are given positive integers n and m.
5 * Define two integers as follows:
6 * 
7 * 	num1: The sum of all integers in the range [1, n] (both inclusive) that are not divisible by m.
8 * 	num2: The sum of all integers in the range [1, n] (both inclusive) that are divisible by m.
9 * 
10 * Return the integer num1 - num2.
11 *  
12 * <strong class="example">Example 1:
13 * 
14 * Input: n = 10, m = 3
15 * Output: 19
16 * Explanation: In the given example:
17 * - 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.
18 * - Integers in the range [1, 10] that are divisible by 3 are [3,6,9], num2 is the sum of those integers = 18.
19 * We return 37 - 18 = 19 as the answer.
20 * 
21 * <strong class="example">Example 2:
22 * 
23 * Input: n = 5, m = 6
24 * Output: 15
25 * Explanation: In the given example:
26 * - 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.
27 * - Integers in the range [1, 5] that are divisible by 6 are [], num2 is the sum of those integers = 0.
28 * We return 15 - 0 = 15 as the answer.
29 * 
30 * <strong class="example">Example 3:
31 * 
32 * Input: n = 5, m = 1
33 * Output: -15
34 * Explanation: In the given example:
35 * - Integers in the range [1, 5] that are not divisible by 1 are [], num1 is the sum of those integers = 0.
36 * - 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.
37 * We return 0 - 15 = -15 as the answer.
38 * 
39 *  
40 * Constraints:
41 * 
42 * 	1 <= n, m <= 1000
43 * 
44 */
45pub struct Solution {}
46
47// problem: https://leetcode.com/problems/divisible-and-non-divisible-sums-difference/
48// discuss: https://leetcode.com/problems/divisible-and-non-divisible-sums-difference/discuss/?currentPage=1&orderBy=most_votes&query=
49
50// submission codes start here
51
52impl Solution {
53    pub fn difference_of_sums(n: i32, m: i32) -> i32 {
54        0
55    }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63
64    #[test]
65    fn test_2894() {
66    }
67}
68


Back
© 2025 bowen.ge All Rights Reserved.