<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 {
public:

    
const int MOD = 1e9 + 7;
int MAX = (1e4+101); 

vector<long long> factorial;
vector<long long> inv_factorial;

Solution()
{
    factorial.assign(MAX+1,1);
    inv_factorial.assign(MAX+1,1);
}

long long mod_pow(long long base, long long exp, long long mod) {
    long long result = 1;
    while (exp > 0) {
        if (exp % 2 == 1) {
            result = (result * base) % mod;
        }
        base = (base * base) % mod;
        exp /= 2;
    }
    return result;
}

void precomputeFactorials() {
    for (int i = 2; i <= MAX; ++i) {
        factorial[i] = factorial[i - 1] * i % MOD;
    }
    inv_factorial[MAX] = mod_pow(factorial[MAX], MOD - 2, MOD);
    for (int i = MAX - 1; i > 0; --i) {
        inv_factorial[i] = inv_factorial[i + 1] * (i + 1) % MOD;
    }
}

long long binomialCoefficient(int n, int k) {
    if (k > n) return 0;
    return factorial[n] * inv_factorial[k] % MOD * inv_factorial[n - k] % MOD;
}
vector<int> primeFactorisation(int num)
{
    vector<int> ans;
    for(int i = 2;i<=sqrt(num);i++)
    {
        while((num%i) == 0)
        {
            ans.push_back(i);
            num /= i;
        }
    }

    if(num != 1)
    {
        ans.push_back(num);
    }

    return ans;
}

    vector<int> waysToFillArray(vector<vector<int>>& queries) 
    {
        int n = 0,k = 0;
        for(auto q:queries)
        {
            n = max(n,q[0]);
            k = max(k,q[1]);
        }
        vector<int> ans;
        // cout << n << " " << k << endl;
        // MAX = max(n,k);
        precomputeFactorials();
        for(auto q : queries)
        {
            int num = q[1];
            int x = q[0];

            long long val = 1;

            auto primes = primeFactorisation(num);
            int count = 1;
            
            if(primes.empty())
                count = 0;
                
            for(int i = 1;i<primes.size();i++)
            {
                if(primes[i] == primes[i-1])
                {
                    count++;
                }
                else
                {
                    val *= (binomialCoefficient(x+count-1,x-1)%MOD);
                    val = val % MOD;

                    count = 1;
                }
            }
            val *= (binomialCoefficient(x+count-1,x-1)% MOD);
            val = val % MOD;

            ans.push_back(val);
        }
       return ans;
    }
};
55100