Sum of Remainders Across Integer Ranges
Updated
Problem statement
Given two nonnegative integers i and j, consider every pair (a, b) with 0 <= a <= i and 1 <= b <= j.
Return the sum of a % b over all these pairs, where % is the remainder after integer division.
The original ranges include zero. For this exercise, pairs whose divisor is zero are excluded because their remainder is undefined. If j = 0, there are no valid pairs and the result is 0.
Function
sumRemainders(i: int, j: int) → longExamples
Example 1
i = 3j = 2return = 2For divisor 1, every remainder is zero. For divisor 2, dividends 0, 1, 2, 3 produce 0, 1, 0, 1. The total is 2.
Example 2
i = 2j = 3return = 4The sums for divisors 1, 2, and 3 are 0, 1, and 3. Their total is 4.
Constraints
0 <= i, j <= 1000000- Return the exact sum as a signed 64-bit integer.
More IBM Online Assessment questions
- Missing IntervalsOA · Seen Nov 2026
- Count Peaks and ValleysOA · Seen Nov 2026
- Last Object Exit TimeOA · Seen Nov 2026
- 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
- Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
- Tree Pythagorean TriplesOA · Seen Oct 2026
- Minimum Power-of-Two Removal OperationsOA · Seen Oct 2026
- Maximum Compatible Time WindowsOA · Seen Oct 2026
Similar questions at other companies
- Count Prime Values in SubtreesVisa · OAVisa interview questions
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Gaussian Naive Bayes Classifier (Machine Learning OA)Pinterest · OAPinterest interview questions
- Bold Play to Reach a GoalSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Count Lucky TicketsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions