Problem · Math

Count Ideal Numbers

EasyIBMFULLTIMEOA
See IBM hiring insights

An ideal number is an integer that can be written as 3^x * 5^y, where x and y are non-negative integers.

Given two integers low and high, count how many ideal numbers are in the inclusive range [low, high].

Examples
01 · Example 1
low = 1
high = 15
return = 5

The ideal numbers in the range are 1, 3, 5, 9, and 15.

02 · Example 2
low = 16
high = 100
return = 5

The ideal numbers in the range are 25, 27, 45, 75, and 81.

Constraints
  • low and high are positive integers.
  • low <= high
More IBM problems
drafts saved locally
public int countIdealNumbers(int low, int high) {
  // write your code here
}
low1
high15
expected5
sign in to submit