← 返回 ibm 的题目列表.NET OA: 3^x * 5^y Count and Decreasing Subarrays
类型:qbank
A Calgary .NET engineer OA contains two easy coding tasks: count numbers of the form `3^x * 5^y` in a range, and count subarrays of length at least two where each next element is one less than the previous.
Requirements
Task 1:
Count how many numbers in a given range can be represented as 3^x * 5^y.
Generate candidates carefully and avoid overflow.
Task 2:
Input: an integer array.
Count subarrays of length at least 2 satisfying arr[i] = arr[i - 1] - 1 for every adjacent pair in the subarray.
Notes
For task 1, nested generation over powers of 3 and 5 is enough when overflow guards are correct.
For task 2, scan maximal runs where every adjacent difference is -1. A run of length L contributes L * (L - 1) / 2 qualifying subarrays of length at least two.
Preparation
For the power-count task, generate powers with division-based overflow guards such as while x <= hi // 3 and deduplicate candidates in a set before range counting.
For the decreasing-subarray task, practise deriving the run formula: every maximal run of length L contributes all choices of start/end with length at least two, L * (L - 1) / 2.