


A special number is a number, which when rotated 180 degrees, resembles some other number in the same range. Every digit of a special number must be a valid digit.
The digits, 0,1,6,8,9, when rotated 180 degrees, become 0,1,9,8,6 respectively. While the digits, 2,3,4,5,7, when rotated do not become any valid digit.
‘8196’, when rotated 180 degrees, will become ‘9618’. We can observe that all the digits of this number are valid. So, this is a special number.
The first line contains an integer ‘T’, which denotes the number of test cases to be run. Then, the T test cases follow.
The first line of each test case contains a single integer, ‘MAXVAL’.
For each test case, print a single integer, denoting the total number of special numbers in the range, 1 to ‘MAXVAL’.
Output for each test case will be printed in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= MAXVAL < 10^4
Time Limit: 1sec
The approach is to loop through all the numbers in the given range one by one and check whether this number is a special number or not. We can check if a number is special or not, by rotating it. This can be achieved by reversing the string representation of the number and thereafter, replacing every ‘6’ by ‘9’ and vice versa.
The approach is to observe the fact that any special number will only have special digits in it. So, instead of checking all the numbers in the range, 1 to ‘MAXVAL’ independently, we can only check numbers that are made up of special digits only. For any special number, we can get more special numbers by appending one of the digits from 0,1,6,8,9 one by one at the end of the special number and check for the new number. The process of checking whether a number is special or not has been discussed in the other approach.
Co-Prime
Fizzbuzz Problem
Print Fibonacci Series
Print Fibonacci Series
Print Fibonacci Series
Print Fibonacci Series
Print Fibonacci Series
Print Fibonacci Series
First Digit One
Special Digit Numbers