No.2649 [Cherry 6th Tune C] Anthem Flower
問題文最終更新日: 2024-02-23 21:36:36
English (AI translation)
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence.
Back to the original
yukicoder contest 418 (Re: start!)
(順位表)
の他の問題:
Story
A group of $M$ people, including Cherry-chan, worked hard for $N$ days to make flowers bloom. As a result, they were able to make $k$ flowers bloom on day $k~(1 \leq k \leq N)$.
In other words, they made a total of $\displaystyle \sum_{k=1}^N k$ flowers bloom over the $N$ days.
Problem Statement
Find the remainder when $\displaystyle \sum_{k=1}^N k$ is divided by $M$.
Solve $T$ test cases.
Constraints
- $1 \leq T \leq 2 \times 10^5$
- Constraints for each test case
- $1 \leq N \lt 10^{4 \times 10^6}$.
- $1 \leq M \leq 10^9$
- Constraints for each test file
- The sum of the numbers of digits of $N$ over the $T$ test cases is at most $4 \times 10^6$.
Input
$T$
${\rm Testcase}_1$
${\rm Testcase}_2$
$\vdots$
${\rm Testcase}_T$
$N$ $M$
Output
The output consists of $T$ lines. On line $t~(1 \leq t \leq T)$, print the answer to test case $t$ as an integer.
Do not forget the newline at the end.
Sample
Sample 1
Input
3 3 100 5 10 123456789012345678901234567890 20240223
Output
6 5 1774557
- [Test case $1$] The remainder when $\displaystyle \sum_{k=1}^3 k=1+2+3=6$ is divided by $100$ is $6$.
- [Test case $2$] The remainder when $\displaystyle \sum_{k=1}^5 k=1+2+3+4+5=15$ is divided by $10$ is $5$.
- [Test case $3$] $N$ can be very large.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
Kazun