A. 破晓狂想曲

传统 2000 ms 1024 MiB
标准 IO
Special Judge

题目描述

Is this the real life? Is this just fantasy?

Caught in a landslide, no escape from reality

Open your eyes, look up to the skies and see

I'm just a poor boy, I need no sympathy

Because I'm easy come, easy go, little high, little low

Any way the wind blows doesn't really matter to me, to me

给定n,mn,m,求

i=1nj=1mgcd(i,j)ij mod 998244353\sum_{i=1}^n\sum_{j=1}^m\frac{\gcd(i,j)}{ij}\ mod\ 998244353

输入格式

第一行,一个数字 t(1t104)t(1\le t \le 10^4),代表数据组数。

对于每组数据,两个整数 n,m(1n,m106)n,m(1\le n,m \le10^6)

输出格式

对于每组数据,输出一行正整数代表答案。

可以证明答案一定可以表示成 qp\frac{q}{p},其中qq为正整数,pp为正整数,且存在一个正整数p(1)p^{(-1)},使得 p(1)×p1 mod 998244353p^{(-1)}×p≡1\ mod\ 998244353,即pp在模998244353998244353下一定存在逆元,你只需输出 q×p(1)q×p^{(-1)}998244353998244353的值即可。

样例

输入样例:

5
1 3
22 13
1000 1000
114 5144
1000000 1000000

输出样例:

831870296
840003385
865445419
863853786
434780206

样例解释:
对于n=1,m=3n=1,m=3,结果为1+12+13=1161+\frac{1}{2}+\frac{1}{3}=\frac{11}{6}1161 mod 998244353=83187029611·6^{-1}\ mod \ 998244353 = 831870296