<p>You are given a 2D integer array, <code>queries</code>. For each <code>queries[i]</code>, where <code>queries[i] = [n<sub>i</sub>, k<sub>i</sub>]</code>, find the number of different ways you can place positive integers into an array of size <code>n<sub>i</sub></code> such that the product of the integers is <code>k<sub>i</sub></code>. As the number of ways may be too large, the answer to the <code>i<sup>th</sup></code> query is the number of ways <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>

<p>Return <em>an integer array </em><code>answer</code><em> where </em><code>answer.length == queries.length</code><em>, and </em><code>answer[i]</code><em> is the answer to the </em><code>i<sup>th</sup></code><em> query.</em></p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> queries = [[2,6],[5,1],[73,660]]
<strong>Output:</strong> [4,1,50734910]
<strong>Explanation:</strong>&nbsp;Each query is independent.
[2,6]: There are 4 ways to fill an array of size 2 that multiply to 6: [1,6], [2,3], [3,2], [6,1].
[5,1]: There is 1 way to fill an array of size 5 that multiply to 1: [1,1,1,1,1].
[73,660]: There are 1050734917 ways to fill an array of size 73 that multiply to 660. 1050734917 modulo 10<sup>9</sup> + 7 = 50734910.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> queries = [[1,1],[2,2],[3,3],[4,4],[5,5]]
<strong>Output:</strong> [1,2,3,10,5]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= queries.length &lt;= 10<sup>4</sup> </code></li>
	<li><code>1 &lt;= n<sub>i</sub>, k<sub>i</sub> &lt;= 10<sup>4</sup></code></li>
</ul>

MOD = 1_000_000_007

def sieve_eratosthenes(n):
    min_prime_factors = list(range(n + 1))
    for i in range(2, int(n**0.5) + 1):
        if min_prime_factors[i] == i:  # i is prime
            for j in range(i * i, n + 1, i):
                if min_prime_factors[j] == j:
                    min_prime_factors[j] = i
    return min_prime_factors

def get_prime_factors_count(num, min_prime_factors):
    count = {}
    while num > 1:
        divisor = min_prime_factors[num]
        while num % divisor == 0:
            num //= divisor
            count[divisor] = count.get(divisor, 0) + 1
    return count

def get_fact_and_inv_fact(n):
    fact = [1] * (n + 1)
    inv_fact = [1] * (n + 1)
    inv = [1] * (n + 1)
    
    for i in range(2, n + 1):
        inv[i] = MOD - MOD // i * inv[MOD % i] % MOD
    
    for i in range(1, n + 1):
        fact[i] = fact[i - 1] * i % MOD
        inv_fact[i] = inv_fact[i - 1] * inv[i] % MOD
    
    return fact, inv_fact

def nCk(n, k, fact, inv_fact):
    if k > n or k < 0:
        return 0
    return fact[n] * inv_fact[k] % MOD * inv_fact[n - k] % MOD

class Solution:
    def waysToFillArray(self, queries):
        kMax = 10_000
        kMaxFreq = 13  # 2^13 = 8192 < kMax
        min_prime_factors = sieve_eratosthenes(kMax + 1)
        fact, inv_fact = get_fact_and_inv_fact(kMax + kMaxFreq - 1)
        ans = []
        
        for n, k in queries:
            res = 1
            for freq in get_prime_factors_count(k, min_prime_factors).values():
                res = res * nCk(n - 1 + freq, freq, fact, inv_fact) % MOD
            ans.append(res)
        
        return ans

22900