Problem · Math

Count Ideal Numbers

Learn this problem
EasyIBM logoIBMFULLTIMEOA
See IBM hiring insights

Problem statement

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].

Function

countIdealNumbers(low: int, high: int) → int

Examples

Example 1

low = 1high = 15return = 5

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

Example 2

low = 16high = 100return = 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
checking account