Sum of Squares of Special Elements
Intuition\nThe problem is asking for the sum of the squares of certain elements in the array. Specifically, for every index i in the array, if the array\'s leng
# Intuition\nThe problem is asking for the sum of the squares of certain elements in the array. Specifically, for every index `i` in the array, if the array\'s length `n` is divisible by `i` (i.e., `n % i == 0`), then the square of the element at that index contributes to the final sum.\n\n# Approach\n1. **Initialize variables**:\n   - `ans` is initialized to 0, which will store the sum of squares.\n   - `n` is assigned the length of the array `nums`.\n   \n2. **Iterate over array elements**:\n   - The loop runs from `i = 1` to `n`, iterating over each index.\n   - For each `i`, check if `n % i == 0`. This determines if `i` is a divisor of the array length `n`.\n   \n3. **Update the result**:\n   - If `i` is a divisor of `n`, take the element at the `i-1` index (because arrays are 0-indexed) and add its square to the running sum `ans`.\n   \n4. **Return the result**:\n   - After processing all valid divisors, return the final value of `ans`.\n\n# Example\n\nIf `nums = [1, 2, 3, 4]`, the length of the array is `4`, and the divisors of 4 are `1, 2, 4`. Hence, the elements at indices `0`, `1`, and `3` are used in the computation:\n\n- Element at index 0: (1^2 = 1)\n- Element at index 1: (2^2 = 4)\n- Element at index 3: (4^2 = 16)\n\nThe result would be (1 + 4 + 16 = 21).\n\n# Complexity\n- **Time Complexity**: \n   - The loop runs from 1 to `n`, making it (O(n)), where `n` is the length of the array `nums`.\n   - Each operation inside the loop (like checking divisibility and calculating the square) is constant time (O(1)), so the overall time complexity is (O(n)).\n\n- **Space Complexity**: \n   - The space complexity is (O(1)) because we are only using a few extra variables (`ans` and `n`) regardless of the input size.\n\n### Code with comments for clarity:\n\n```java\nclass Solution {\n    public int sumOfSquares(int[] nums) {\n        int ans = 0; // Variable to hold the sum of squares\n        int n = nums.length; // Length of the array\n\n        for (int i = 1; i <= n; i++) { // Loop from 1 to the length of the array\n            int div = n % i; // Check if i is a divisor of n\n            if (div == 0) {\n                // Add the square of nums[i-1] to the result if n is divisible by i\n                ans = ans + (nums[i - 1] * nums[i - 1]);\n            }\n        }\n        return ans; // Return the final sum of squares\n    }\n}\n```\n\nThis code efficiently computes the sum of squares for the elements whose indices divide the length of the array.
['Array', 'Enumeration', 'Java']