FastPrepSum Symmetric Pairwise Remainders
Problems/Sum Symmetric Pairwise Remainders

Sum Symmetric Pairwise Remainders

Confluent logoConfluent● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Confluent online assessment. The report gives the formula, the ranges of ordered pairs, a numeric limit, and the modulus. Our version is about 99% the same as the reported question.

You are given a positive integer n. For positive integers i and j, define C(i, j) = (i % j) + (j % i), where % is the remainder after integer division.

Return the sum of C(i, j) over every ordered pair satisfying 1 <= i <= n and 1 <= j <= n, modulo 10^9 + 7.

Both (i, j) and (j, i) occur when i != j. Pairs with i = j are included and contribute 0.

Function

sumPairwiseRemainders(n: int) → int

Examples

Example 1

n = 2return = 2

C(1, 1) = 0, C(1, 2) = 1, C(2, 1) = 1, and C(2, 2) = 0. Their sum is 2.

Example 2

n = 1return = 0

The only pair is (1, 1), and both remainders are zero.

Example 3

n = 4return = 24

For divisors 1, 2, 3, and 4, the sums of i % j over i = 1..4 are 0, 2, 4, and 6. Their sum is 12. Swapping the two indices gives the same aggregate for j % i, so the required total is 24.

Constraints

  • 1 <= n <= 10^6.
  • Return an integer in [0, 10^9 + 6].

More Confluent interview questions

  • Hard Disk Clustering CostOA · Seen Nov 2026
  • Last Object to Fall Off the TableOA · Seen Nov 2026
  • 0/1 KnapsackOA · Seen Nov 2026
  • Count Combinations Using Weights One Through KOA · Seen Oct 2026
  • Reach Target BalanceOA · Seen Mar 2026
  • Tail N LinesOA · Seen Mar 2026
  • Implement tail -nPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Sudoku Board ValidationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Sudoku Puzzle SolverPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Match a Variadic Function SignaturePHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Count Distinct Arrays After Decrement OperationsBloomberg LP · OABloomberg LP interview questions
  • Polynomial CoefficientsShopify · OAShopify interview questions
  • Basic Calculator IITypeSafe AI · OA
  • Last Object Exit TimeIBM · OAIBM interview questions
  • 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

Interview reports that mention this question

  • Confluent SWE OA, Coding and Design Interviews: 19 Experiences

Confluent interview experiences

  • Confluent Older Concurrency Rounds: 12 Experiences (Part 2 of 2)
  • Confluent Concurrency Interviews: 28 Experiences (Part 1 of 2)
  • Confluent File Manipulation Round (tail -n): 19 Experiences
  • Confluent Coding and System Design Questions: 33 Questions
All Confluent interview questionsSee Confluent hiring insights
Saved
class Solution {
    public int sumPairwiseRemainders(int n) {
        // Write your code here.
    }

}
Checking account…