Consider,
F4(y) = the number of digits 4 in decimal representation of the positive integer y
and
F7(y)=the number of digits '7' in decimal representation of the positive integer y.
For the given positive integer N ,Find the total number of different pairs (L, R)
such that F4(L) + F4(L + 1) + ... + F4(R) equals to F7(L) + F7(L + 1) + ... + F7(R)
and 1 ≤ L ≤ R ≤ N.
Examples::
N=1 Ans::1
N=2 Ans::3
N=3 Ans::6
N=4 Ans::6
N=5 Ans::7
N=6 Ans::9
N=7 Ans::13
N=8 Ans::18
N=9 Ans::24
N=10 Ans::31
N=11 Ans::39
N=12 Ans::48
N=13 Ans::58
N=14 Ans::61
N=15 Ans::65
N=16 Ans::70
N=17 Ans::81
N=18 Ans::93
N=19 Ans::106
N=20 Ans::120
How to solve this problem Efficiently??