1
from collections import Counter2
from functools import lru_cache3
from typing import List, Tuple5
PRIMES = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29)11
def factor(n) -> Tuple[int, bool]:13
:param n: 1 < n <= max(PRIMES)14
:return: (factors in bit mask, has duplicate primes)19
while n > 1 and n % e == 0:36
def numberOfGoodSubsets(self, nums: List[int]) -> int:40
if 1 < e and (fr := factor(e))[1]:44
good_nums = Counter({0: 0})47
for f in tuple(good_nums):48
if f & mask: # some prime dividing "mask" is also dividing the "f"53
count_for_new_mask = good_nums[new_mask] + cnt[mask] * (57
good_nums[new_mask] = count_for_new_mask % BIG_NUMBER59
effect_of_one = pow(2, nums.count(1), BIG_NUMBER)60
total_subsets_without_one = sum(good_nums.values()) % BIG_NUMBER62
return (effect_of_one * total_subsets_without_one) % BIG_NUMBER