close

LUCIFER - LUCIFER Number


Lucifer is the only human who has defeated Ra-One in a computer game ...

Ra-One is after Lucifer for revenge and G-One is there to protect him ...

All the G-One and Ra-One nonsense has disturbed Lucifer's life ...

He wants to get rid of Ra-One and kill him. He found that Ra-One can be killed only by throwing Lucifer number of weapons at him.

Lucifer number shares the some properties of Ra-One Numbers numbers and G-One Numbers

Any number is LUCIFER NUMBER if the difference between sum of digits at even location and sum of digits at odd location is prime number. For example, 20314210 is a Lucifer number:

digits at odd location 0, 2, 1, 0.

digits at even location 1, 4, 3, 2.

difference = (1+4+3+2)-(0+2+1+0) = 10-3 = 7 ... a prime number.

Lucifer has access to a warehouse that has lots of weapons. He wants to know in how many ways can he kill him.

Can you help him?

Input

First line will have a number 't' denoting the number of test cases.

each of the following t lines will have 2 numbers 'a', 'b'

Output

Print single number per test case, depicting the count of Lucifer numbers in the range a, b inclusive.

Example

Input:
5
200 250
150 200
100 150
50 100
0 50
Output: 2
16
3
18
6

NOTE: t will be less than 100. 'a' and 'b' will be between 0 and 109 inclusive.


hide comments
Image ujjwala0001: 2024-05-13 16:36:47

how answer for 0 to 50 is 6? the numbers are 2,3,5,7,20,30,31,41,42,50 considering 0 based indexing from L to R
UPD: Anyone having same issues, actually indexing has been considered from R to L and is 1-based so digit that you are adding will contribute depending upon its position from end ,i.e, length - index.

Last edit: 2024-05-13 17:01:54
Image akgupta0777: 2024-04-16 16:09:49

Solved myself after learning concepts of Digit DP.

Image mushfiq123: 2024-04-15 20:08:40

Great problem, but little unclear, but not really, you see when they showcased the digits for even and odd places in the question, they maintained the order from right to left where the right most number is considered as index 1 , good question , I personally used 4D dp, but there are other ways as well

Image anuragdw0710: 2023-04-16 16:49:54

If any one is struck with dp part first solve "Ra-One Numbers" on spoj.

Image dpw4112001: 2021-11-20 17:17:51

This problem is pretty unclear. Got AC after a lot of considerations which are not mentioned.

Image biber_2222: 2021-10-25 19:15:51

this is giving tle for python code even after memoization

Image manujk: 2020-11-17 11:38:12

Read @iceelement comment for further clarification of the problem. Though the problem is easy, the statement is a bit incomplete.

Last edit: 2020-11-17 11:38:52
Image manish_thakur: 2020-05-24 05:52:50

Why does this always involve Ra one and G one

Image saurav_555: 2020-03-26 23:02:09

After solving GONE AND RAONE....
like Easy peasy...

Image iceelement: 2019-01-25 04:56:21

I think this question requires further clarifications. Difference here means the signed difference between even and odd positions. The positioning is considered from right to left with 1 based indexing. Negative numbers are not considered prime, even if their absolute value is prime.


Added by:Devil D
Date:2012-03-09
Time limit:0.100s-0.5s
Source limit:10000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own