E - Sequence of Multiples 解説 /

実行時間制限: 6 sec / メモリ制限: 1024 MB

配点 : 800800

問題文

整数 N,XN, X が与えられます。整数列 A=(A1,,AN)A = (A_1, \ldots, A_N) が次の条件をすべて満たすとします。

  • A1=XA_1 = X
  • 任意の ii (1iN1\leq i\leq N) に対して、AiA_iii の倍数である。
  • AA は狭義単調増加である。つまり、A1<<ANA_1 < \cdots < A_N が成り立つ。

i=1NAi\sum_{i=1}^N A_i として考えられる最小値を、998244353998244353 で割った余りを求めてください。

TT 個のテストケースが与えられるので、それぞれについて答えを求めてください。

制約

  • 1T101\leq T\leq 10
  • 1N10181\leq N \leq 10^{18}
  • 1X10181\leq X \leq 10^{18}

入力

入力は以下の形式で標準入力から与えられます。

TT
case1\text{case}_1
\vdots
caseT\text{case}_T

各テストケースは以下の形式で与えられます。

NN XX

出力

TT 行出力してください。ii 行目には、casei\text{case}_i に対する答えを出力してください。


入力例 1Copy

Copy
5
5 100
1 10
10 1
1000000000000000000 1
100 100

出力例 1Copy

Copy
525
10
55
75433847
61074

はじめの 33 つのテストケースについて、例えば次の AAi=1NAi\sum_{i=1}^N A_i の最小値を与えます:

  • 11 番目のテストケース:A=(100,102,105,108,110)A = (100, 102, 105, 108, 110)
  • 22 番目のテストケース:A=(10)A = (10)
  • 33 番目のテストケース:A=(1,2,3,4,5,6,7,8,9,10)A = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

Score : 800800 points

Problem Statement

You are given integers NN and XX. Assume that an integer sequence A=(A1,,AN)A = (A_1, \ldots, A_N) satisfies all of the conditions below.

  • A1=XA_1 = X.
  • For every ii (1iN1\leq i\leq N), AiA_i is a multiple of ii.
  • AA is strictly increasing. In other words, A1<<ANA_1 < \cdots < A_N holds.

Find the minimum possible value of i=1NAi\sum_{i=1}^N A_i, modulo 998244353998244353.

There are TT test cases, each of which should be solved.

Constraints

  • 1T101\leq T\leq 10
  • 1N10181\leq N \leq 10^{18}
  • 1X10181\leq X \leq 10^{18}

Input

Input is given from Standard Input from the following format:

TT
case1\text{case}_1
\vdots
caseT\text{case}_T

Each case is in the following format:

NN XX

Output

Print TT lines. The ii-th line should contain the answer for casei\text{case}_i.


Sample Input 1Copy

Copy
5
5 100
1 10
10 1
1000000000000000000 1
100 100

Sample Output 1Copy

Copy
525
10
55
75433847
61074

Here is a sequence AA that minimizes i=1NAi\sum_{i=1}^N A_i for each of the first three test cases.

  • The first test case: A=(100,102,105,108,110)A = (100, 102, 105, 108, 110).
  • The second test case: A=(10)A = (10).
  • The third test case: A=(1,2,3,4,5,6,7,8,9,10)A = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).


2025-04-05 (土)
07:08:52 +00:00