JZPEXT - Beautiful numbers EXTREME

We call one integer beautiful, if and only if it is divisible by each of its non-zero digits. Given an interval [l, r], calculate how many beautiful numbers n satisfy l<=n<=r.

Input

First line, the number of test cases, t.

Then t lines follow, each line two numbers l, r, representing the query interval [l, r].

1<=t<=2.5*10^4

1<=l<=r<=10^18

Output

t lines. The t-th line is the answer to the t-th query.

Example

Input:
1
1 100

Output:
33

Added by:sevenkplus
Date:2011-01-17
Time limit:1s
Source limit:1024B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All

hide comments
2024-02-06 09:44:06
Stupid question with a stupid source code limit.

Last edit: 2024-02-06 09:44:30
2022-04-19 06:01:17
Are you serious to set the source code limit to 1KB?
2017-09-09 12:36:06
can someone give me an optimized code my code is running but the time complexity for large input is very high
2015-07-21 17:42:58 Scape
What is the damn purpose of this problem? And why the hell source limit? I wasted 2 hours optimizing my solution only to find out it's too long. Got AC afterwards but this problem sucks hard.
2013-12-12 11:05:36 Sourangsu
Not much fun in solving this...

Last edit: 2013-12-12 11:06:35
2013-09-01 14:04:16 South_stream
who can tell me the real answer....I can't do it .. TLE always..
2012-01-30 15:44:50 [Rampage] Blue.Mary
Resource: Codeforces Beta Round #55.

BTW, I don't like this problem. It needs heavy constant optimization, for example, I use array u[][] to store the result of (a*10+b)%C. (C is some constant.)

Last edit: 2012-01-30 16:38:21
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.