<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:
    int MD = 1e9+7;
    vector<int> prime_list;
    long long fact[20001];

    void get_fact(){
        fact[0] = 1;
        for(int i = 1; i <= 2e4; i++){
            fact[i] = (fact[i-1] * i) % MD;
        }
    }

    long long power(long long x, int y){ // return x^y % MD O(log y)
        long long ret = 1;
        while(y > 0){
            if((y & 1) == 1){
                ret *= x;
                ret %= MD;
            }
            x *= x;
            x %= MD;
            y >>= 1;
        }
        return ret;
    }

    long long mod_inv(int x){
        return power(x, MD-2) % MD;
    }

    int comb(int n, int r){
        if(n < r) return 0;
        if(r == 0) return 1;
        return (fact[n] * mod_inv(fact[r]) % MD) * mod_inv(fact[n-r]) % MD;
    }

    void get_prime(){ // return the prime list <= k
        for(int i = 2; i <= 1e4; i++){
            bool isPrime = true;
            for(int p : prime_list){
                if(i % p == 0){
                    isPrime = false;
                    break;
                }
            }
            if(isPrime){
                prime_list.push_back(i);
            }
        }
    }

    vector<int> prime_factors(int k){
        vector<int> ret;
        for(int p : prime_list){
            if(p > k) break;
            int cnt = 0;
            while(k % p == 0){
                k /= p;
                cnt++;
            }
            if(cnt > 0)
                ret.push_back(cnt);
        }
        return ret;
    } // 6 -> {1, 1}

    vector<int> waysToFillArray(vector<vector<int>>& queries) {
        get_prime();
        get_fact();
        vector<int> ans;
        for(vector<int> q : queries){
            int n = q[0], k = q[1];
            vector<int> factors = prime_factors(k);
            long long cnt = 1;
            for(int e : factors){
                cnt *= comb(e+n-1, e);
                cnt %= MD;
            }
            ans.push_back(cnt);
        }
        return ans;
    }
};

/*
1. find the prime factors for k.
-> 6 = 2*3
consider a number k is p1^e1*p2^e2+...
for each slot, we can pick any number from e1, e2, ...
we formulate the k into an array {e1, e2, e3, ...}
assume that we have n slots, then we are going to place
e1 of 2s, e2 of 3s, ... into n slots.
we have
C(n+e1-1, n) * C(n+e2-1, n) * ...

4, 4
{2}
x1+x2+x3+x4 = 2
0 <= xi for all i.

H(4,2) = C(4+2-1, 2) = C(5, 2) = 10

2, 6
{1,1}
x1+x2=1, xi >= 0
C(2+1-1, 1)
*/
40400