Lucifer is the only human whi has defeated RA-ONE in a computer game ..

RA-One is after lucifer for revenge and G-One is there to protect him ...

All thi G-One and Ra-one Nonsense has disturbed lucifers 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 eg... for 20314210 is lucifer number

digits at odd location 0,2,1,0

digits at even location 1,4,3,2

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

Lucifer has access to a Warehouse which has lots of weapons ..

He wants to know in how many ways can he kill him.

Can you help him?



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'


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



200 250
150 200
100 150
50 100
0 50


NOTE: t will be less than 100
from and to will be between 0 and 10^9 inclusive

hide comments
Darko Aleksic: 2012-08-21 22:31:26

Time limit seems to be too tight - can the problem setter submit a reference solution in one of the languages that has not been accepted yet? Say Java or Python. Otherwise, limit it to C/C++/Pas.

Surya kiran: 2012-04-06 09:55:24

aaaah...can the size limit of the problem be increased ????

Devil D: 2012-04-06 09:55:24

Only 2 numbers 240 & 250 r Lucifer ...
For 200,201 , 203 the dfference is -ve

Mitch Schwartz: 2012-04-06 09:55:24

@Erben: We are not considering negative numbers as prime.

Erben: 2012-04-06 09:55:24

Are there only 2 Lucifer numbers in the range of 200-250?


There are more than 2 Lucifer numbers. Is this example true? Or what did I do wrong? What does this problem want?

Devendar: 2012-04-06 09:55:24

getting time limit exceeded..... any clues

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