Count the Number of Ideal Arrays - Problem
You are given two integers n and maxValue, which are used to describe an ideal array.
A 0-indexed integer array arr of length n is considered ideal if the following conditions hold:
- Every
arr[i]is a value from1tomaxValue, for0 <= i < n. - Every
arr[i]is divisible byarr[i - 1], for0 < i < n.
Return the number of distinct ideal arrays of length n. Since the answer may be very large, return it modulo 10^9 + 7.
Input & Output
Example 1 — Basic Case
$
Input:
n = 2, maxValue = 3
›
Output:
5
💡 Note:
The 5 ideal arrays are: [1,1], [1,2], [1,3], [2,2], [3,3]. Each array satisfies: all elements ≤ 3, and each element divides the next.
Example 2 — Longer Array
$
Input:
n = 3, maxValue = 2
›
Output:
4
💡 Note:
The 4 ideal arrays are: [1,1,1], [1,1,2], [1,2,2], [2,2,2]. All arrays have length 3 with elements ≤ 2.
Example 3 — Single Element
$
Input:
n = 1, maxValue = 4
›
Output:
4
💡 Note:
With length 1, any single value is ideal: [1], [2], [3], [4]. No divisibility constraint applies.
Constraints
- 2 ≤ n ≤ 104
- 1 ≤ maxValue ≤ 104
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given n=2, maxValue=3
2
Generate
Find all arrays where each element divides the next
3
Count
Return total count: 5 ideal arrays
Key Takeaway
🎯 Key Insight: Ideal arrays follow divisibility chains, making this a combinatorial counting problem with prime factorization
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code