Consider the following:
How many numbers exist between
0x100 and 0x111? 100,101,110,111 ( 4 = 0x111 - 0x100 + 1 )
How many total unlucky numbers exist between 744 and 777 (744 747 774 777).
Now:
700 and 800 have the same number of unlucky numbers between them as 744 and 777. 744 is the smallest unlucky number, greater than 700, and 777 is the largest unlucky number, less than 800.
No need to generate numbers, just subtraction.
For cases like a = 10, b = 800, first find your number for 10-100, and then 100-800 (because you will count several numbers twice):
For 10-100:
a = 44 b = 77 0x11 - 0x00 = 3 + 1 = 4 ( 44,47,74,77 )
For 100-800:
a = 444 b = 777 0x111 - 0x000 = 7 + 1 = 8 ( 444, 447, 474, 477, 744, 747, 774, 777 )
So between 10 and 800: 4 + 8 = 12 numbers, which is also correct.
It is also O (1) time and space if you find auxiliary numbers efficiently, which should not be too heavy ...