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

X-liked Counting

Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 312    Accepted Submission(s): 71


Problem Description
David is alway fond of new kinds of numbers.

He defines a number $x-liked$ if any of its prefixes or suffixes can be divided by $x$. A prefix is a contiguous part which begins at the leftmost position of the number and ends at any position of the number, and a suffix is a contiguous part which begins at any position of the number and ends at the rightmost position of the number. For example, $12$ is a prefix of $123$ while $23$ is a suffix of it. The number itself can be a prefix or a suffix of itself.

Now David wants to know how many $x-liked$ integers there are in the range $[l,r]$. However, since David doesn't like the number $7$, he won't allow digit $7$ to occur in the numbers, so you don't need to count in numbers like $27$,$372$,$774$ etc. because they all have at least one digit equals to $7$. Please tell him how many $x-liked$ integers there are in the range $[l,r]$ with no digit equals to $7$.
 

Input
The first line contains one integer $T$($1 \leq T \leq 10$) , the number of testcases.

For each testcase, there is one line which contains three non-negative integers, $l$,$r$ and $x$.

$1 \leq l \leq r \leq 10^{18}$
$1 \leq x \leq 500$
 

Output
For each testcase, output one number in one line, how many $x-liked$ integers there are in the range $[l,r]$ with no digit equals to $7$.
 

Sample Input
1 11 20 4
 

Sample Output
5
 

Hint
In the sample, there are five valid integers, 12(12 can be divided by 4), 14(4 can be divided by 4), 16(16 can be divided by 4), 18(8 can be divided by 4), 20(20 and 0 both can be divided by 4).
 

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-06-26 17:39:47, Gzip enabled