Find the Number of Subsequences With Equal GCD

You are given an integer array nums.

Your task is to find the number of pairs of non-empty subsequences (seq1, seq2) of nums that satisfy the following conditions:

  • The subsequences seq1 and seq2 are disjoint, meaning no index of nums is common between them.
  • The GCD of the elements of seq1 is equal to the GCD of the elements of seq2.

Return the total number of such pairs.

Since the answer may be very large, return it modulo 10^9 + 7.

Example 1
Inputnums = [1,2,3,4]
Output10
There are 10 ordered pairs of disjoint non-empty subsequences whose GCDs are both equal to 1.
Example 2
Inputnums = [10,20,30]
Output2
There are 2 ordered pairs of disjoint non-empty subsequences whose GCDs are both equal to 10.

Constraints

  • 1 <= nums.length <= 200
  • 1 <= nums[i] <= 200

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