CNT_LUCK - Counting Lucky Numbers

Find out how many numbers between a and b (inclusive) when represented as binary numbers have sum of digits lucky.

A number is lucky if its decimal representation contains digits 4 and 7 only.

eg. 4, 7, 47, 77 etc. where as 14, 41 etc. are not.

Note that 0 <= a <= b <= 10^19.

Input

T: number of test cases T<=10^5

Next T lines have a and b in every line. a <= b

Output

for every test case output as described in problem statement

Example

Input:
2
15 15
63 63

Output:
1
0

Added by:praveen123
Date:2013-01-21
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:general

hide comments
2013-02-22 10:00:20 STARK
please explain the test case... :\
2013-02-22 10:00:20 praveen123
@sahil sareen; You are looping over i from a to b, O(b) where b is 10^19 ,
Multiplying it by no of test cases 10^5 is 10^24. It is huge. Improve the complexity of code.

Last edit: 2013-01-25 20:18:56
2013-02-22 10:00:20 SAHIL SAREEN
@pravin123 Could u please give me some hint .. getting TLE 8579705
@Tjandra where can i learn the low level C++ from?
2013-02-22 10:00:20 (Tjandra Satria Gunawan)(曾毅昆)
@praveen123: Could you change the cluster to pyramid and rejudge all submissions, I think it's better using pyramid cluster to see more accurate running time on each submission.
2013-02-22 10:00:20 (Tjandra Satria Gunawan)(曾毅昆)
It's binary level code (low level), just like assembly, hard to write but very fast...
2013-02-22 10:00:20 praveen123
awesome , I could not understand even a line of code what you wrote :(
2013-02-22 10:00:20 (Tjandra Satria Gunawan)(曾毅昆)
yay! finally 0.02s ;-) now it's superhard to break my time record :-D
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.