Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3671 - Sum of Beautiful Subsequences.

    Hard

    You are given an integer array nums of length n.

    For every positive integer g, we define the beauty of g as the product of g and the number of strictly increasing subsequences of nums whose greatest common divisor (GCD) is exactly g.

    Return the sum of beauty values for all positive integers g.

    Since the answer could be very large, return it modulo <code>10<sup>9</sup> + 7</code>.

    Example 1:

    Input: nums = 1,2,3

    Output: 10

    Explanation:

    All strictly increasing subsequences and their GCDs are:

    Calculating beauty for each GCD:

    Total beauty is 5 + 2 + 3 = 10.

    Example 2:

    Input: nums = 4,6

    Output: 12

    Explanation:

    All strictly increasing subsequences and their GCDs are:

    Calculating beauty for each GCD:

    Total beauty is 2 + 4 + 6 = 12.

    Constraints:

    • <code>1 <= n == nums.length <= 10<sup>4</sup></code>

    • <code>1 <= numsi<= 7 * 10<sup>4</sup></code>

    • 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 totalBeauty(IntArray nums)
      • Methods inherited from class java.lang.Object

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