Humble Numbers
InterviewTime limit1sMemory limit128 MB
For each n up to 5842, print the nth number whose only prime factors are 2, 3, 5, or 7, formatted with the correct English ordinal suffix.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
A number whose only prime factors are 2, 3, 5, or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... lists the first 20 humble numbers.
Write a program that finds and prints the th element of this sequence.
Input
The input consists of one or more test cases. Each test case is a single integer (). The input is terminated by a line containing , which is not processed.
Output
For each test case, print exactly one line in the following format:
The <n><suffix> humble number is <number>.
Here <number> is the th humble number, and <suffix> is the correct English ordinal suffix for ("st", "nd", "rd", or "th"). For example, 1 becomes "1st", 2 becomes "2nd", 3 becomes "3rd", while 11, 12, and 13 become "11th", "12th", and "13th".