From 1d06cbd973a590dc5d23b669995fe8da13540f84 Mon Sep 17 00:00:00 2001 From: Kiril Kovachev Date: Fri, 8 Mar 2024 21:04:44 +0000 Subject: [PATCH] Solve 2778. Sum of Squares of Special Elements in Rust --- rust/2778_sum_of_squares_of_special_elements.rs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 rust/2778_sum_of_squares_of_special_elements.rs diff --git a/rust/2778_sum_of_squares_of_special_elements.rs b/rust/2778_sum_of_squares_of_special_elements.rs new file mode 100644 index 0000000..f0c3806 --- /dev/null +++ b/rust/2778_sum_of_squares_of_special_elements.rs @@ -0,0 +1,9 @@ +impl Solution { + pub fn sum_of_squares(nums: Vec) -> i32 { + let n = nums.len(); + nums.iter().enumerate() + .filter(|(i, x)| n % (i+1) == 0) + .map(|(i, x)| x*x) + .sum() + } +} \ No newline at end of file