F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Sumire

Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1344    Accepted Submission(s): 457


Problem Description
Calculate

$$
\sum_{i=l}^r f^k(i,B,d)
$$

where $f(x,B,d)$ means the number of times that digit $d$ appears in the base-$B$ form of $x$ (ignoring leading zeros).

In this problem, we consider that $0^0=0$.
 

Input
The first line contains one integer $T$ ($1\le T\le 10^4)$, denoting the number of test cases.

For each test case, the only line contains five integers $k,B,d,l,r$ ($0\le k\le 10^9$, $2\le B\le 10^9$, $0\le d< B$, $1\le l\le r\le 10^{18})$, as the statement shows.
 

Output
For each test case, output an integer indicating the answer modulo $10^9+7$ in a single line.
 

Sample Input
3 2 2 0 1 5 1 4 3 11 45 10 14 11 19 198
 

Sample Output
6 19 1049
 

Hint
For the first case in the sample, the answer is

$$
\begin{aligned}
&\sum_{i=1}^5 f^2(i,2,0)\\\\
&=0^2+1^2+0^2+2^2+1^2\nonumber\\\\
&=6\nonumber
\end{aligned}
$$
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-04 12:28:13, Gzip enabled