Count Ideal Numbers in a Range
Problem statement
An ideal number is a positive integer that can be written as 3^x * 5^y, where x and y are non-negative integers.
For example, 15, 45, and 75 are ideal numbers, while 6, 10, and 21 are not. The number 1 is also ideal because both exponents can be zero.
Given integers low and high, return the number of ideal numbers in the inclusive range [low, high].
Function
getIdealNums(low: int, high: int) → intExamples
Example 1
low = 200high = 405return = 4The four ideal numbers are 225 = 3^2 * 5^2, 243 = 3^5 * 5^0, 375 = 3^1 * 5^3, and 405 = 3^4 * 5^1. All four lie in the inclusive range.
Example 2
low = 1high = 1return = 1The only number in this range is 1 = 3^0 * 5^0, so it is an ideal number.
Example 3
low = 6high = 14return = 1The only ideal number in this range is 9 = 3^2 * 5^0.
Constraints
- For this exercise, assume
1 <= low <= high <= 2^31 - 1.