Divide and Mod

View as PDF

Submit solution

Points: 3
Time limit: 1.0s
Memory limit: 64M

Problem type

Write a program that answers the following question Q times:

Given three integers A, B, and C, find the integer N where \lfloor \frac N A \rfloor = B and N \equiv C \pmod A.


1 \le Q \le 10^5

1 \le A, B, C \le 10^9

Input Specification

The first line contains Q. The following Q lines contain 3 integers A, B, and C.

Output Specification

For each question, output on a separate line N, the integer that satisfies the conditions.

Sample Input

6 5 11

Sample Output



N = 35 satisfies both conditions when A = 6, B = 5, C = 11: \lfloor \frac{35}{6} \rfloor = 5, and 35 \equiv 11 \pmod 6.


  • 0
    gavin_chen  commented on July 20, 2022, 8:16 p.m. edited

    what does the ≡ symbol in the equations mean I looked all around the internet and could not identify what is means other then "identical to" which doesn't explain 35 ≡ 11. Please help.

    • 3
      maxcruickshanks  commented on July 22, 2022, 3:33 p.m.

      It is a modular congruence symbol.

      • 0
        gavin_chen  commented on July 26, 2022, 8:19 p.m. edited

        Oh that help a lot guess I didn't think BOTH 35 and 11 are moded (and out of all places the answer was it was khan academy (why))