2844. Sum of Squares of Special Elements
My accepted C++ solution to LeetCode problem 2844, Sum of Squares of Special Elements, running in 0ms.
- Difficulty: Easy
- C++
- Runtime 0ms
- Memory 40MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 40MB, accepted 2025-12-27.
class Solution {
public:
int sumOfSquares(vector<int>& nums) {
int n = nums.size(), sum = 0;
for (int i = 1; i <= n; i++) {
if (n % i == 0) sum += nums[i-1] * nums[i-1];
}
return sum;
}
};