FastPrepSum of Remainders Across Integer Ranges
Problems/Sum of Remainders Across Integer Ranges

Sum of Remainders Across Integer Ranges

IBM logoIBM● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IBM online assessment. The report does not say which direction the remainder goes, how to handle a zero divisor, the function signature, or the limits on the numbers. Here the left values are the dividends and zero divisors are left out. Our version is about 95% the same as the reported question.

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) → long

Examples

Example 1

i = 3j = 2return = 2

For 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 = 4

The 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

IBM interview experiences

  • IBM Full-Time SWE OA Questions: 1 Experience
  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public long sumRemainders(int i, int j) {
        // Write your code here
    }
}
Checking account…