#P16808. [蓝桥杯 2026 国 Python A] 连续丢卡

    ID: 19149 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>数学二分2026蓝桥杯国赛

[蓝桥杯 2026 国 Python A] 连续丢卡

Problem Description

Xiao Lan originally had a set of cards, with the numbers 1,2,…,n1, 2, \ldots, n written on them, exactly one card for each number.

Later, Xiao Lan found that LL consecutive cards were missing from this set. That is, there exists a positive integer aa such that the cards numbered a,a+1,…,a+L−1a, a+1, \ldots, a+L-1 are all missing, where a+L−1≤na+L-1 \le n.

After the loss happened, Xiao Lan added up the numbers on all remaining cards, and the total sum is SS.

Now, given the sum SS of the remaining cards and the number LL of missing cards, please compute the sum of all possible original total counts nn of cards. If there is no nn that satisfies the conditions, the answer is 00. The same valid nn 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 nn modulo 998244353998244353.

Input Format

The first line contains a positive integer TT, indicating the number of queries.

The next TT lines each contain two positive integers SS and LL, separated by a space.

Output Format

Output TT lines. Each line contains one integer, representing the sum of all possible nn for the corresponding query modulo 998244353998244353.

4
10 2
15670 27
20 3
35 1
11
579
0
8

Hint

Sample Explanation

For the first query, S=10,L=2S = 10, L = 2.

  • When n=5n = 5, it is possible to lose the two cards numbered 2,32, 3, and the sum of the remaining card numbers is 1010.
  • When n=6n = 6, it is possible to lose the two cards numbered 5,65, 6, and the sum of the remaining card numbers is 1010.

Therefore, the possible values of nn are 55 and 66, and the answer is 5+6=115 + 6 = 11.

Constraints and Notes

For 30%30\% of the testdata, 1≤T≤51 \le T \le 5, 1≤S≤1061 \le S \le 10^6, 1≤L≤201 \le L \le 20.

For all testdata, 1≤T≤1051 \le T \le 10^5, 1≤S≤10181 \le S \le 10^{18}, 1≤L≤1001 \le L \le 100.

Translated by ChatGPT 5