Skip to content

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 * 3
  • 8 = 1 * 2 * 4
  • 10 = 1 * 2 * 5
  • 12 = 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 * 5
  • 126 = 1 * 3 * 6 * 7
  • 128 = 1 * 2 * 4 * 16

 

Constraints:

  • 3 <= k <= 100
  • 1 <= l <= r <= 106

Solutions

Solution 1

1

1

1

1

Comments