Number of Different Subsequences GCDs LeetCode solution in Python
1import math234class Solution:5def countDifferentSubsequenceGCDs(self, nums: List[int]) -> int:6max_n = max(nums) + 17seen = set(nums)89ans = 010for k in range(1, max_n): # iterate candidate k11gcd = 012for multiple in range(13k, max_n, k14): # compute gcd of all array multiples of k15if multiple in seen:16gcd = math.gcd(gcd, multiple)17if gcd == k: # check the candidate18ans += 119return ans