Count Ways to Make Array With Product - Problem

You are given a 2D integer array queries. For each queries[i], where queries[i] = [ni, ki], find the number of different ways you can place positive integers into an array of size ni such that the product of the integers is ki.

As the number of ways may be too large, the answer to the ith query is the number of ways modulo 109 + 7.

Return an integer array answer where answer.length == queries.length, and answer[i] is the answer to the ith query.

Input & Output

Example 1 — Basic Query
$ Input: queries = [[2,6],[3,1]]
Output: [4,1]
💡 Note: For [2,6]: arrays [1,6], [2,3], [3,2], [6,1] all have product 6, so 4 ways. For [3,1]: only [1,1,1] has product 1, so 1 way.
Example 2 — Single Element
$ Input: queries = [[1,10]]
Output: [1]
💡 Note: Array of size 1 with product 10: only [10] works, so 1 way.
Example 3 — Larger Array
$ Input: queries = [[4,2]]
Output: [4]
💡 Note: Arrays of size 4 with product 2: [2,1,1,1], [1,2,1,1], [1,1,2,1], [1,1,1,2], so 4 ways.

Constraints

  • 1 ≤ queries.length ≤ 104
  • 1 ≤ ni ≤ 104
  • 1 ≤ ki ≤ 104

Visualization

Tap to expand
Count Ways to Make Array With ProductQuery: [2, 6]n=2, k=6Prime Factorization6 = 2¹ × 3¹CombinatoricsStars and BarsValid arrays:[1, 6][2, 3][3, 2][6, 1]Answer: 4 ways
Understanding the Visualization
1
Input
Queries with array size n and target product k
2
Process
Use prime factorization and combinatorics
3
Output
Count of valid arrangements for each query
Key Takeaway
🎯 Key Insight: Transform multiplication constraints into combinatorial distribution of prime factors
Asked in
Google 25 Microsoft 18 Amazon 15
15.6K Views
Medium Frequency
~35 min Avg. Time
420 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen