Class Solution
-
- All Implemented Interfaces:
public final class Solution3671 - Sum of Beautiful Subsequences.
Hard
You are given an integer array
numsof lengthn.For every positive integer
g, we define the beauty ofgas the product ofgand the number of strictly increasing subsequences ofnumswhose greatest common divisor (GCD) is exactlyg.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>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegertotalBeauty(IntArray nums)-
-
Method Detail
-
totalBeauty
final Integer totalBeauty(IntArray nums)
-
-
-
-