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 nn cities in their country, numbered from 11 to nn . And the traffic system in the country is very special. For each city ii ( 1in1 \le i \le n ), there is

  • a road between city ii and 2i2i , if 2in2i\le n ;
  • a road between city ii and 2i+12i+1 , if 2i+1n2i+1\le n .

Making a travel plan, Daniel chooses some integer value between 11 and mm for each city, for the ii -th city we denote it by aia_i .

Let si,js_{i,j} be the maximum value of cities in the simple ^\dagger path between cities ii and jj . The score of the travel plan is i=1nj=insi,j\sum_{i=1}^n\sum_{j=i}^n s_{i,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 998244353998\,244\,353 .

^\dagger A simple path between cities xx and yy is a path between them that passes through each city at most once.

输入格式

The first line of input contains a single integer tt ( 1t2001\le t\le 200 ) — the number of test cases. The description of test cases follows.

The only line of each test case contains two integers nn and mm ( 1n10181\leq n\leq 10^{18} , 1m1051\leq m\leq 10^5 ) — the number of the cities and the maximum value of a city.

It is guaranteed that the sum of mm over all test cases does not exceed 10510^5 .

输出格式

For each test case output one integer — the sum of scores of all possible travel plans, modulo 998244353998\,244\,353 .

输入输出样例

  • 输入#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 111\rightarrow 1 : s1,1=a1=1s_{1,1}=a_1=1 .

Path 121\rightarrow 2 : s1,2=max(1,1)=1s_{1,2}=\max(1,1)=1 .

Path 131\rightarrow 3 : s1,3=max(1,1)=1s_{1,3}=\max(1,1)=1 .

Path 222\rightarrow 2 : s2,2=a2=1s_{2,2}=a_2=1 .

Path 2132\rightarrow 1\rightarrow 3 : s2,3=max(1,1,1)=1s_{2,3}=\max(1,1,1)=1 .

Path 333\rightarrow 3 : s3,3=a3=1s_{3,3}=a_3=1 .

The score is 1+1+1+1+1+1=61+1+1+1+1+1=6 .

In the second test case, there are four possible travel plans:

Score of plan 11 : 1+1+1=31+1+1=3 .

Score of plan 22 : 1+2+2=51+2+2=5 .

Score of plan 33 : 2+2+1=52+2+1=5 .

Score of plan 44 : 2+2+2=62+2+2=6 .

Therefore, the sum of score is 3+5+5+6=193+5+5+6=19 .

首页