Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    2778 - Sum of Squares of Special Elements.

    Easy

    You are given a 1-indexed integer array nums of length n.

    An element nums[i] of nums is called special if i divides n, i.e. n % i == 0.

    Return the sum of the squares of all special elements of nums.

    Example 1:

    Input: nums = 1,2,3,4

    Output: 21

    Explanation:

    There are exactly 3 special elements in nums: nums1 since 1 divides 4, nums2 since 2 divides 4, and nums4 since 4 divides 4.

    Hence, the sum of the squares of all special elements of nums is nums1 \* nums1 + nums2 \* nums2 + nums4 \* nums4 = 1 \* 1 + 2 \* 2 + 4 \* 4 = 21.

    Example 2:

    Input: nums = 2,7,1,19,18,3

    Output: 63

    Explanation:

    There are exactly 4 special elements in nums: nums1 since 1 divides 6, nums2 since 2 divides 6, nums3 since 3 divides 6, and nums6 since 6 divides 6.

    Hence, the sum of the squares of all special elements of nums is nums1 \* nums1 + nums2 \* nums2 + nums3 \* nums3 + nums6 \* nums6 = 2 \* 2 + 7 \* 7 + 1 \* 1 + 3 \* 3 = 63.

    Constraints:

    • 1 <= nums.length == n <= 50

    • 1 <= nums[i] <= 50

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer sumOfSquares(IntArray nums)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait