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

class Solution {
    void buildSieve(vector<bool>& v) {
        for (int i=0, n=v.size(); i<n; i++) {
            if (v[i]) {
                for (int j=i<<1; j<n; j+=i) v[j]=false;
            }
        }
    }
    
    void factorize(vector<int>& primes, unordered_map<int, int>& f, int x) {
        if (x==1) return;        
        for (int p:primes) {
            if (p>x) break;
            if (x%p==0) {
                f[p]++;
                factorize(primes, f, x/p);
                break;
            }
        }
    }
public:
    vector<int> waysToFillArray(vector<vector<int>>& queries) {
        const int M=1000000007;
        vector<bool> temp(10001, true);
        temp[0]=temp[1]=false;
        buildSieve(temp);
        
        vector<int> primes;
        for (int i=2, n=temp.size(); i<n; i++) {
            if (temp[i]) primes.push_back(i);
        }
        
        int maxn=0;
        for (auto& q:queries) maxn=max(maxn, q[0]+16);
        
        vector<vector<int>> C(maxn, vector<int>(15, 1));
        for (int i=2, n=C.size(); i<n; i++) {
            for (int j=1, m=min(15, i); j<m; j++) {
                C[i][j]=(C[i-1][j-1]+C[i-1][j])%M;
            }
        }
        
        vector<int> ans;
        unordered_map<int, unordered_map<int, int>> pf;
        for (auto& q:queries) {
            if (pf.count(q[1])==0) {
                factorize(primes, pf[q[1]], q[1]);
            }
            auto& f=pf[q[1]];

            long count=1;
            for (auto [v, r]:f) {
                count=count*C[q[0]+r-1][r]%M;
            }
            ans.push_back(count);
        }
        return ans;
    }
};
65700