QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 1024 MB Total points: 100

#3004. It's a Mod, Mod, Mod, Mod World

統計

Problem Description

You are given multiple problems with three integers $p$, $q$, and $n$. Find $\sum^n_{i=1}[(pi) \bmod q]$. That is, the first $n$ multiples of $p$, modulo $q$, summed. Note that the overall sum has no modulus.

Input

Each input will begin with a line with a single integer $W$ ($1 \leq W \leq 10^5$), which is the number of cases you must solve.

Each of the next $W$ lines will contain three space-separated integers $p$, $q$ and $n$ ($1\leq p, q, n \leq 10^6$), which are the parameters of the problem as described above.

Output

Output $W$ lines, each with the answer for a given instance of the problem, in the order that they appear in the input.

Sample

Sample Input

3
2 7 2
1 4 5
3 8 10

Sample Output

6
7
37

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.