#P16098. [ICPC 2019 NAIPC] It' s a Mod, Mod, Mod, Mod World

[ICPC 2019 NAIPC] It' s a Mod, Mod, Mod, Mod World

题目描述

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

输入格式

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

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

输出格式

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

3
2 7 2
1 4 5
3 8 10
6
7
37