#P16808. [蓝桥杯 2026 国 Python A] 连续丢卡
[蓝桥杯 2026 国 Python A] 连续丢卡
Problem Description
Xiao Lan originally had a set of cards, with the numbers written on them, exactly one card for each number.
Later, Xiao Lan found that consecutive cards were missing from this set. That is, there exists a positive integer such that the cards numbered are all missing, where .
After the loss happened, Xiao Lan added up the numbers on all remaining cards, and the total sum is .
Now, given the sum of the remaining cards and the number of missing cards, please compute the sum of all possible original total counts of cards. If there is no that satisfies the conditions, the answer is . The same valid is counted only once even if it corresponds to multiple ways of losing cards.
Since the answer may be very large, you only need to output the sum of all such modulo .
Input Format
The first line contains a positive integer , indicating the number of queries.
The next lines each contain two positive integers and , separated by a space.
Output Format
Output lines. Each line contains one integer, representing the sum of all possible for the corresponding query modulo .
4
10 2
15670 27
20 3
35 1
11
579
0
8
Hint
Sample Explanation
For the first query, .
- When , it is possible to lose the two cards numbered , and the sum of the remaining card numbers is .
- When , it is possible to lose the two cards numbered , and the sum of the remaining card numbers is .
Therefore, the possible values of are and , and the answer is .
Constraints and Notes
For of the testdata, , , .
For all testdata, , , .
Translated by ChatGPT 5