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

// 2024-08-06, 星期二, 七月初三, 甲辰年, 龙年, 辛未月, 壬寅日
// https://github.com/shionryuu/leetcode-rust
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}

class Comb {
private:
  const long long MOD;
  int n;
  vector<long long> fact; 
  vector<long long> inv_fact; 

public:
  Comb(int n, long long MOD = 1e9 + 7) : MOD(MOD), n(n), fact(n + 1, 0), inv_fact(n + 1, 0) {
    fact[0] = inv_fact[0] = 1;
    for (int i = 1; i <= n; ++i) {
      fact[i] = fact[i - 1] * i % MOD;
    }
    inv_fact[n] = binpow(fact[n], MOD - 2, MOD);
    for (int i = n - 1; i >= 0; --i) {
      inv_fact[i] = inv_fact[i + 1] * (i + 1) % MOD;
    };
  }

  int nCr(int n, int r) {
    if (r < 0 || r > n) {
      return 0;
    }
    return fact[n] * inv_fact[r] % MOD * inv_fact[n - r] % MOD;
  }
};

std::once_flag flag;
static std::array<bool, 20'001> is_primes;
static vector<int> primes;

void sieve_once() {
  std::call_once(flag, []() {
    size_t len = is_primes.size();
    is_primes.fill(true);
    is_primes[0] = false;
    is_primes[1] = false;
    for (long long i = 2; i < len; i++) {
      if (!is_primes[i]) {
        continue;
      }
      primes.push_back(i);
      for (long long j = i * i; j < len; j += i) {
        is_primes[j] = 0;
      }
    }
  });
}

class Solution {
public:
  // 2024-08-06, 星期二, 七月初三, 甲辰年, 龙年, 辛未月, 壬寅日
  // https://github.com/shionryuu/leetcode-rust
  vector<int> waysToFillArray(vector<vector<int>>& queries) {
    const long long MOD = 1e9 + 7;
    sieve_once();
    Comb comb(2e4 + 1);
    vector<int> ans;
    for (auto query : queries) {
      int box = query[0];
      int num = query[1];
      long long ways = 1;
      for (size_t i = 0; i < primes.size() && num >= primes[i]; ++i) {
        if (num % primes[i] == 0) {
          int cnt = 0;
          while (num % primes[i] == 0) {
            num /= primes[i];
            ++cnt;
          }
          ways = ways * comb.nCr(box + cnt - 1, cnt) % MOD;
        }
      }
      ans.push_back(ways);
    }
    return ans;
  }
};
58800