What are the algorithms to find all numbers consisting 3 and 5 only in the given range L and R (both inclusive)

We have to find out all the numbers consisting of 3 and 5 only in a given range L and R(inclusive).

What are the possible approaches to do this task?

Given that,

1 <= L <= R <= 10^9.

Not sure but maybe finding everydigit of all numbers between range L and R.Complexity O((r-l)*(no.of digits)).
i am also newbie so expert correct me if i am wrong

Your approach will surely give tle.

Range Query problem…A naive approach would be to use brute force in the range and find the numbers…
Efficient algorithms include the use of segment trees …U can study about them here


i hope that helped !!

you can use below method
L-left index R-right index
I-counter
algorithm find_number:-
1.Set I:=L;
2. Repeat while I<=R
1) Set q:=1 and num=I;
2) Repeat while q!=0
a)q:=num/10
b)rem:=num%10
c) if rem=3 or rem=5 then print(I) and I=I+1 and goto step 2.1
d) else num:=q
3)I=I+1
3.Exit

@vank thanks for guiding me…

a solution can be made from this idea…
you are having l and r .
you know number of digits in the number r and number l .
now check out that at an index how many digits you can use .
most probabily its a dp problem and might use inclusion exclusion .