Count Sequences to K
You are given an integer array nums, and an integer k.
Start with an initial value val = 1 and process nums from left to right. At each index i, you must choose exactly one of the following actions:
- Multiply
valbynums[i]. - Divide
valbynums[i]. - Leave
valunchanged.
After processing all elements, val is considered equal to k only if its final rational value exactly equals k.
Return the count of distinct sequences of choices that result in val == k.
Note: Division is rational (exact), not integer division. For example, 2 / 4 = 1 / 2.
Example 1
Input
nums = [2,3,2], k = 6Output
2There are 2 distinct choice sequences that end with an exact final value of 6.
Example 2
Input
nums = [4,6,3], k = 2Output
2There are 2 distinct choice sequences that end with an exact final value of 2.
Constraints
- 1 <= nums.length <= 19
- 1 <= nums[i] <= 6
- 1 <= k <= 10^15