Sum of Beautiful Subsequences

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 10^9 + 7.

Example 1
Inputnums = [1,2,3]
Output10
The total beauty is 5 + 2 + 3 = 10 across GCDs 1, 2, and 3.
Example 2
Inputnums = [4,6]
Output12
The total beauty is 2 + 4 + 6 = 12 across GCDs 2, 4, and 6.

Constraints

  • 1 <= n == nums.length <= 10^4
  • 1 <= nums[i] <= 7 * 10^4

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate