问题 I: Colorings Counting

内存限制:512 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:0

题目描述

Given a ring of n nodes. It's required to color each node with one of the colors in 0∼m−1, and ensure that adjacent points have different colors.

Consider two colorings are different if and only if two colorings sequences a, b cannot be transformed into each other through several of the following three operations:


Calculate the different colorings, modulo 998244353.


输入格式

The input consists of multiple test cases. The first line contains a single integer T(1T100) - the number of test cases. Description of the test cases follows.

The first line of each test case contains two integer n, m (4n10182m1018).

It's guaranteed that n, mare not multiples of 998244353.

It's guaranteed that there will be no more than 40 test cases with n, m > 20.

It's guaranteed that there will be no more than 20 test cases with n, m > 10 ^ 5.

It's guaranteed that there will be no more than 5 test cases with n,m>1013.

 

输出格式

For each test case, print a single integer - the different colorings, modulo 998244353.

输入样例 复制

4
4 2
4 3
6 3
2023 808

输出样例 复制

1
2
5
304535191

分类标签