Problem 418584 · medium · Phase 04 Non-Linear Data Structures

Nth 5-Smooth Number

heaps · number generation · deduplication · sets

A positive integer is 5-smooth if its only prime factors are 2, 3 and 5. Counting 1 as the first, the sequence begins 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, ... (7, 11, 13 and 14 are missing because 7, 11 and 13 are not allowed factors).

Given n, return the n-th 5-smooth number.

Examples

Input:  n = 10
Output: 12

Input:  n = 1
Output: 1

Constraints

  • 1 <= n <= 20000 (answers exceed 32-bit range; Python integers are fine)
  • Target complexity: O(n log n).

Goals

  • Generate an ordered sequence by expanding the smallest candidate
  • Avoid duplicate candidates with a visited set
  • Stop after exactly n pops
Starting Python…