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.
Complete the function countPowerProductsInRange in the editor below.
countPowerProductsInRange has the following parameters:
long low: the lower bound of the rangelong high: the upper bound of the range
Returns
int: the number of integers in [low, high] that can be expressed as 3x * 5y.
Examples
01 · Example 1
low = 1 high = 15 return = 5
The valid numbers in the range are 1, 3, 5, 9, 15. Therefore, the answer is 5.
02 · Example 2
low = 16 high = 100 return = 5
The valid numbers in the range are 25, 27, 45, 75, 81. Therefore, the answer is 5.
Constraints
The source thread did not provide explicit numeric bounds.
xandyare non-negative integers.- Only values within the inclusive range
[low, high]should be counted. - Implementations should avoid overflow when generating powers of
3and5.
More IBM problems
- Count Ideal NumbersOA · Seen Jun 2026
- Count Descending SubarraysOA · Seen Apr 2026
- Minimum Operations to Make Alternating Binary StringSeen Feb 2026
- Minimum Number of Non-Empty Disjoint SegmentsSeen Feb 2026
- Count Unstable ProcessesOA · Seen Feb 2026
- Longest Balanced Binary SubarrayOA · Seen Feb 2026
- Process Execution TimeOA · Seen Nov 2025
- Service Timeout DetectionOA · Seen Nov 2025
public int countPowerProductsInRange(long low, long high) {
// write your code here
}
low1
high15
expected5
sign in to submit