luogu#P4900. 食堂

    ID: 3879 远端评测题 404ms 40MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>O2优化素数判断,质数,筛法前缀和逆元

食堂

Background

Even if I, CYJian, were to die, die outside, or jump off from here, I would still not eat a single bite of cafeteria food.

So tasty..\color{white}\text{So tasty..}

Problem Description

On day ii, the cafeteria has ii dishes. CYJian thinks the tastiness of the jj-th dish on day ii is {ij}\left\{\dfrac{i}{j}\right\} (where {}\{\} means taking the fractional part). Of course, CYJian is someone who likes to try things, so he will eat a little of every dish.

Now CYJian has TT queries. Each query asks for the total tastiness gained from day AiA _ i to day BiB _ i. Please help him compute it. Output the answer modulo 998244353998244353.

Input Format

The first line contains an integer TT.

The next TT lines each contain two integers, representing AA and BB for each query.

Output Format

Output TT lines, each containing a positive integer representing the sum of tastiness.

If the answer can be written as PQ\dfrac{P}{Q}, then you need to find any xx such that Q×xP(mod998244353)Q \times x \equiv P \pmod{998244353}, and output xmod998244353x \bmod 998244353.

1
1 3

499122177

Hint

Sample Explanation

On day 1 the tastiness is 0.000.00. On day 2 the tastiness is 0.00+0.00=0.000.00+0.00=0.00. On day 3 the tastiness is 0.00+0.50+0.00=0.500.00+0.50+0.00=0.50. Thus 0.00+0.00+0.50=0.50=120.00+0.00+0.50=0.50=\dfrac{1}{2}. Since 499122177×21(mod998244353)499122177 \times 2 \equiv 1 \pmod{998244353}, the answer is 499122177499122177.

Constraints

This problem uses bundled testdata.

Subtask Range T=T = ABA \le B \le
151 \sim 5 11 50005000
6106 \sim 10 10610^6
101510 \sim 15 10610^6 50005000
162016 \sim 20 10610^6

Translated by ChatGPT 5