#P15662. [ICPC 2025 Jakarta R] Maximeter

[ICPC 2025 Jakarta R] Maximeter

题目描述

Solve the problem below for TT test cases.

You are given two integers MM and DD. You are interested in a rooted weighted tree with the following conditions.

  • Each edge has a weight of a positive integer.
  • For each vertex vv of the tree, there exists no\textbf{no} set of vv's children of size strictly greater\textbf{strictly greater} than MM such that all the edges connecting vv and this set of children all have the same weight.
  • The diameter of the tree is not greater than DD. The diameter of a tree is the maximum distance between any two vertices.

Find the maximum number of vertices of such a tree. As the number of vertices can be very large, find the vertex count modulo 998  244  353998\;244\;353.

输入格式

The first line contains an integer TT (1T1001 \leq T \leq 100), the number of test cases.

Each of the next TT lines contains two integers MM and DD (1M,D1091 \leq M, D \leq 10^9) representing a case you have to solve.

输出格式

For each of the TT test cases, output a single line containing the maximum number of vertices modulo 998  244  353998\;244\;353.

3
2 4
165 1
20 20
12
2
891869870

提示

Explanation of Sample 1:\textit{Explanation of Sample 1:} The following illustrates, for the first case, a rooted tree with the maximum number of vertices.

:::align{center} :::