#P7750. [2019年杭电多校]Rikka with Segment Tree
[2019年杭电多校]Rikka with Segment Tree
Rikka with Segment Tree
Problem Description
Rikka is a master of data structures and Segment tree is Rikka's favorite data structure. This problem is a simple exercise about it. Given a positive integer , the segment tree on can be built by a recursive process: Starting with , suppose the current interval is , the process recursively builds subtrees for $\left[l, \left \lfloor \frac{l+r}{2} \right\rfloor\right], \left[ \left \lfloor \frac{l+r}{2} \right \rfloor + 1, r \right]$ until . For example, when , there are intervals on the segment tree: $[1,1],[2,2],[3,3],[4,4],[5,5],[1,2],[4,5],[1,3],[1,5]$. To explore the structure of segment trees, Rikka defines a magic function which represents the depth of node on a segment tree on (the depth of the root is defined as ). For example, . Now Rikka gives you two positive integers , and she wants you to calculate:
$$\sum_{n=L}^R \sum_{i=1}^n \left(f(i,n) \times i \right) $$Input
The first line of the input contains a single integer , the number of test cases. For each test case, the input contains a single line with two positive integers .
Output
For each test case, output a single line with a single integer, the answer. The answer may be very large, you only need to output the answer modulo .
Sample Input
5
4 4
1 4
1 10
1 100
1 1000
Sample Output
30
52
843
1236922
763123843
Source
2019 Multi-University Training Contest 9