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