4129. Count K-Products in Range π
DifficultyHard
Description
You are given 3 positive integers k, l, and r.
A positive integer n is a k-product if n is a product of k distinct positive integers. For example, 8 is a 3-product because 8 = 1 * 2 * 4.
Return an integer denoting the number of k-products between l and r (inclusive).
Example 1:
Input: k = 3, l = 1, r = 12
Output: 4
Explanation:
The 3-products are 6, 8, 10, 12.
6 = 1 * 2 * 38 = 1 * 2 * 410 = 1 * 2 * 512 = 1 * 3 * 4
Example 2:
Input: k = 4, l = 120, r = 128
Output: 3
Explanation:
The 4-products are 120, 126, 128.
120 = 2 * 3 * 4 * 5126 = 1 * 3 * 6 * 7128 = 1 * 2 * 4 * 16
Constraints:
3 <= k <= 1001 <= l <= r <= 106
Solutions
Solution 1
1 | |
1 | |
1 | |
1 | |