<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>

MODULUS = int(1e9 + 7)  # Modulus value for calculations to prevent overflow
MAX_VALUE = 10020  # Maximum value for pre-computation

class Solution:
    def __init__(self):
        self.factorial = [1] * MAX_VALUE  # Cache for factorial values
        self.inverse_factorial = [1] * MAX_VALUE  # Cache for inverse factorial values
        self.prime_factors_counts = [[] for _ in range(MAX_VALUE)]  # Lists to store counts of prime factors for each number
        self.precompute()  # Precompute values during initialization

    # Function to calculate modular inverse using fast exponentiation
    def mod_inverse(self, a, p):
        res = 1
        k = p - 2
        while k > 0:
            if k % 2 == 1:
                res = res * a % p
            a = a * a % p
            k //= 2
        return res

    # Pre-compute factorials, inverse factorials, and prime factors counts
    def precompute(self):
        for i in range(1, MAX_VALUE):
            self.factorial[i] = self.factorial[i - 1] * i % MODULUS
            self.inverse_factorial[i] = self.mod_inverse(self.factorial[i], MODULUS)
            x = i
            j = 2
            while j * j <= x:
                if x % j == 0:
                    count = 0
                    while x % j == 0:
                        count += 1
                        x //= j
                    self.prime_factors_counts[i].append(count)
                j += 1
            if x > 1:
                self.prime_factors_counts[i].append(1)

    # Function to calculate combination C(n, k) using precomputed factorials
    def combination(self, n, k):
        if k > n or k < 0:
            return 0
        return self.factorial[n] * self.inverse_factorial[k] % MODULUS * self.inverse_factorial[n - k] % MODULUS

    # Given an array of queries, calculate the number of ways to fill an array for each query
    def waysToFillArray(self, queries):
        result = []
        for query in queries:
            n, k = query
            total_ways = 1
            for prime_factor_count in self.prime_factors_counts[k]:
                total_ways = total_ways * self.combination(prime_factor_count + n - 1, n - 1) % MODULUS
            result.append(total_ways)
        return result

22900