#3671

Sum of Beautiful Subsequences

hard · 31.3% accepted · 35 likes · top 9%

array · math · binary indexed tree · number theory

Description

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 109 + 7.

Solution