Logo
(追記) (追記ここまで)

16998번 - It’s a Mod, Mod, Mod, Mod World 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 512 MB109650834649.358%

문제

You are given multiple problems with three integers p, q, and n. Find \(\displaystyle\sum_{i=1}^{n}{((p \cdot i) \text{ mod } q)}\). That is, the first n multiples of p, modulo q, summed. Note that the overall sum has no modulus.

입력

Each input will begin with a line with a single integer W (1 ≤ W ≤ 105), 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 ≤ p, q, n ≤ 106), which are the parameters of the problem as described above.

출력

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

제한

예제 입력 1

3
2 7 2
1 4 5
3 8 10

예제 출력 1

6
7
37

힌트

출처

University > North American Invitational Programming Contest > NAIPC 2019 D번

Contest > Open Cup > 2018/2019 Season > Stage 14: Grand Prix of America D번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /