#P6826. 「EZEC-4」月下轻花舞

「EZEC-4」月下轻花舞

Background

The light flowers under the moon, dancing with the gentle breeze, bring back memories of you and me......

Problem Description

In the Light-Flower Forest, there are light-flower trees numbered from ll to rr. For the tree numbered ii, there are i1i - 1 such trees. The Light-Flower Forest is very beautiful, so each tree has nn light flowers numbered 1n1\sim n. If the light flower numbered jj on the tree numbered ii falls, it produces a charm value of logij\left\lceil\log_i j\right\rceil.

When night falls, all light flowers on all trees fall. The "flower fan" (just kidding) tlx wants to know the total charm value, but calculating it only once is too easy, so he will set up different scenarios and ask you TT times. Since the answer is very large, you only need to output the total charm value modulo 998244353998244353.

One-sentence statement: There are TT queries. Each time you are given three integers l,r,nl, r, n, and you need to compute the value of the following expression:

$$\sum_{i=l}^r(i-1)\sum_{j=1}^n \left\lceil\log_ij\right\rceil\;\;\bmod998244353$$

Input Format

The first line contains an integer TT, representing the number of queries.

The next TT lines each contain three integers l,r,nl, r, n, representing the starting tree index, the ending tree index, and the number of light flowers on each tree.

Output Format

Output TT lines. Each line contains one integer, representing the result of each query modulo 998244353998244353.

1
2 3 5
20
2
23333 23333 233233
114514 19260817 1919810   
356712294
125194507

Hint

Constraints

This problem uses bundled testdata. The specific constraints are as follows:

  • Subtask 1 (1 pts)(1\text{ pts}): T=1T = 1, n=1n = 1.
  • Subtask 2 (9 pts)(9\text{ pts}): l=r=2l = r = 2.
  • Subtask 3 (10 pts)(10\text{ pts}): T=1T = 1, n103n\leq 10^3, r103r\leq 10^3.
  • Subtask 4 (10 pts)(10\text{ pts}): l=r2l = r\not=2.
  • Subtask 5 (20 pts)(20\text{ pts}): T=1T = 1, n106n\leq 10^6.
  • Subtask 6 (20 pts)(20\text{ pts}): T=1T = 1, r106r\leq 10^6.
  • Subtask 7 (20 pts)(20\text{ pts}): T3000T\leq 3000.
  • Subtask 8 (10 pts)(10\text{ pts}): No special restrictions, time limit 1.5  s1.5\;\text{s}.

For all testdata, it holds that:

1T1051\leq T\leq 10^5, 1n10181\leq n\leq 10^{18}, 2lr10182\leq l\leq r\leq 10^{18}.

Note: Any constraints not mentioned in the subtasks use the maximum constraints.


Sample Explanation #1

$$\left\lceil\log_21\right\rceil+\left\lceil\log_22\right\rceil+\left\lceil\log_23\right\rceil+\left\lceil\log_24\right\rceil+\left\lceil\log_25\right\rceil=8$$$$\left\lceil\log_31\right\rceil+\left\lceil\log_32\right\rceil+\left\lceil\log_33\right\rceil+\left\lceil\log_34\right\rceil+\left\lceil\log_35\right\rceil=6$$

Therefore:

ans=8×(21)+6×(31)=20ans=8×(2-1)+6×(3-1)=20

For Sample #2, I believe your smart brain can get the answer in no time.


Other Hints

If you do not understand logarithm (log\log) operations, you can check here.

Translated by ChatGPT 5