CF1868C.Travel Plan
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
During the summer vacation after Zhongkao examination, Tom and Daniel are planning to go traveling.
There are n cities in their country, numbered from 1 to n . And the traffic system in the country is very special. For each city i ( 1≤i≤n ), there is
- a road between city i and 2i , if 2i≤n ;
- a road between city i and 2i+1 , if 2i+1≤n .
Making a travel plan, Daniel chooses some integer value between 1 and m for each city, for the i -th city we denote it by ai .
Let si,j be the maximum value of cities in the simple † path between cities i and j . The score of the travel plan is ∑i=1n∑j=insi,j .
Tom wants to know the sum of scores of all possible travel plans. Daniel asks you to help him find it. You just need to tell him the answer modulo 998244353 .
† A simple path between cities x and y is a path between them that passes through each city at most once.
输入格式
The first line of input contains a single integer t ( 1≤t≤200 ) — the number of test cases. The description of test cases follows.
The only line of each test case contains two integers n and m ( 1≤n≤1018 , 1≤m≤105 ) — the number of the cities and the maximum value of a city.
It is guaranteed that the sum of m over all test cases does not exceed 105 .
输出格式
For each test case output one integer — the sum of scores of all possible travel plans, modulo 998244353 .
输入输出样例
输入#1
5 3 1 2 2 10 9 43 20 154 147
输出#1
6 19 583217643 68816635 714002110
说明/提示
In the first test case, there is only one possible travel plan:
Path 1→1 : s1,1=a1=1 .
Path 1→2 : s1,2=max(1,1)=1 .
Path 1→3 : s1,3=max(1,1)=1 .
Path 2→2 : s2,2=a2=1 .
Path 2→1→3 : s2,3=max(1,1,1)=1 .
Path 3→3 : s3,3=a3=1 .
The score is 1+1+1+1+1+1=6 .
In the second test case, there are four possible travel plans:
Score of plan 1 : 1+1+1=3 .
Score of plan 2 : 1+2+2=5 .
Score of plan 3 : 2+2+1=5 .
Score of plan 4 : 2+2+2=6 .
Therefore, the sum of score is 3+5+5+6=19 .