CNT_LUCK - Counting Lucky Numbers

no tags 

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

hide comments
STARK: 2013-02-22 10:00:20

please explain the test case... :\

praveen123: 2013-02-22 10:00:20

@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
SAHIL SAREEN: 2013-02-22 10:00:20

@pravin123 Could u please give me some hint .. getting TLE 8579705
@Tjandra where can i learn the low level C++ from?

(Tjandra Satria Gunawan)(曾毅昆): 2013-02-22 10:00:20

@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.

(Tjandra Satria Gunawan)(曾毅昆): 2013-02-22 10:00:20

It's binary level code (low level), just like assembly, hard to write but very fast...

praveen123: 2013-02-22 10:00:20

awesome , I could not understand even a line of code what you wrote :(

(Tjandra Satria Gunawan)(曾毅昆): 2013-02-22 10:00:20

yay! finally 0.02s ;-) now it's superhard to break my time record :-D


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