😎😎😎 Easiest Java Solution For This Problem 😎😎😎
Intuition
The goal is to sum the squares of elements in the array whose indices divide the length of the array evenly. By iterating through each index and check
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
- The goal is to sum the squares of elements in the array whose indices divide the length of the array evenly. By iterating through each index and checking if it divides the array length, we identify the "special" elements. We then square these elements and accumulate their sum to return the final result.
---
# Approach
<!-- Describe your approach to solving the problem. -->
1. **Understand the Problem:**
- You are given a 1-indexed array `nums` of length `n`.
An element `nums[i]` is considered special if its index `i` divides `n` evenly (i.e., n%i==0).
- The task is to return the sum of the squares of all special elements in the array.
2. **Iterate Over the Array:**
- For each index `i` (0-based, but treat it as `i+1` for 1-based index):
-> Check if `n%(i+1)==0`.
-> If the index is special, square the element `nums[i]` and add it to the sum.
3. **Return the Result:**
- After looping through all the elements, return the accumulated sum of squares of the special elements.
---
# Complexity
- **Time complexity:** $$O(n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- **Space complexity:** $$O(1)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
---
# Code
```Java []
class Solution {
    public int sumOfSquares(int[] nums) {
        int n = nums.length, sum = 0;

        for (int i = 0; i < n; i++) 
        {
            if (n % (i + 1) == 0)
                sum = sum + (nums[i] * nums[i]);
        }
        return (sum);
    }
}
```
```C++ []
class Solution {
public:
    int sumOfSquares(vector<int>& nums) {
        int n = nums.size(), sum = 0;

        for (int i = 0; i < n; i++) 
        {
            if (n % (i + 1) == 0)
                sum = sum + (nums[i] * nums[i]);
        }
        return (sum);
    }
};
```
```C []
int sumOfSquares(int* nums, int numsSize) {
    int n = numsSize, sum = 0;

    for (int i = 0; i < n; i++) 
    {
        if (n % (i + 1) == 0)
            sum = sum + (nums[i] * nums[i]);
    }
    return (sum);
}
```
---
![sution section image.jpeg](https://assets.leetcode.com/users/images/dbc58e2f-1b82-4df5-b5f6-3695b4920ea0_1737110426.9000046.jpeg)

['Array', 'C', 'C++', 'Java']