For a subsequence , retains exactly the prime powers whose exponents are equal in every chosen element. For example, and retain only , giving .
Write if and . Such a divisor is obtained by keeping or discarding each entire prime-power factor of . Let and compute . Count the frequency of each value and enumerate all subset products of its prime-power factors.
Let count subsequences with . Initialize . Process , subtracting from for every with . The answer is
with all calculations performed modulo .
Precomputing smallest prime factors and powers of gives time and space per case.
Proof
After operations choosing a prime , an exponent becomes . Equal exponents are best left unchanged. Unequal exponents can become equal only when all reach zero. Hence retains exactly the positive prime powers shared with identical exponents by all chosen elements.
It follows that holds exactly when for every chosen element. Therefore,
Since every proper divisor is smaller than its value, processing values in decreasing order finalizes before subtracting its contribution from smaller divisors.
Every enumerated divisor is also an ordinary divisor, so their total number is at most .