FastPrepCount Power Products in Range
Problems/Count Power Products in Range

Count Power Products in Range

IBM logoIBM● EasyFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Given two integers low and high, count how many integers in the inclusive range [low, high] can be written in the form 3x * 5y, where x and y are non-negative integers.

Each valid value should be counted once, even if there is only one way to generate it. The value 1 is valid because 1 = 30 * 50.

Function

countPowerProductsInRange(low: long, high: long) → int

Complete the function countPowerProductsInRange in the editor below.

countPowerProductsInRange has the following parameters:

  1. long low: the lower bound of the range
  2. long high: the upper bound of the range

Returns int: the number of integers in [low, high] that can be expressed as 3x * 5y.

Examples

Example 1

low = 1high = 15return = 5

The valid numbers in the range are 1, 3, 5, 9, 15. Therefore, the answer is 5.

Example 2

low = 16high = 100return = 5

The valid numbers in the range are 25, 27, 45, 75, 81. Therefore, the answer is 5.

Constraints

  • No numeric limits are given for this problem.
  • x and y are non-negative integers.
  • Only values within the inclusive range [low, high] should be counted.
  • Implementations should avoid overflow when generating powers of 3 and 5.

More IBM problems

  • Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
  • Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
  • Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public int countPowerProductsInRange(long low, long high) {
        // write your code here
    }

}
Checking account…