feat: 2894_divisible_and_non_divisible_sums_difference

This commit is contained in:
SquidSpirit 2025-08-18 18:10:42 +08:00
parent d259727b80
commit 476faf16f8
3 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "divisible_and_non_divisible_sums_difference"
version = "0.1.0"

View File

@ -0,0 +1,6 @@
[package]
name = "divisible_and_non_divisible_sums_difference"
version = "0.1.0"
edition = "2024"
[dependencies]

View File

@ -0,0 +1,14 @@
fn main() {
println!("Hello, world!");
}
struct Solution;
impl Solution {
pub fn difference_of_sums(n: i32, m: i32) -> i32 {
let (dividable, undividable): (Vec<i32>, Vec<i32>) =
(1..(n + 1)).partition(|&val| val % m == 0);
undividable.iter().sum::<i32>() - dividable.iter().sum::<i32>()
}
}