This is seen in the geeksforgeeks when a problem, very good, the topic is
Given a number system with only 3 and 4. Find the nth number in the number system.
First few numbers in the number system Are:3, 4, 33, 34, 43, 44, 333, 334, 343, 344,
433, 434, 443, 444, 3333, 3334, 3343, 3344, 3433, 3434, 3443, 3444, ...
(Topic link)
To put it simply, it is:
Find the nth number in a sequence of numbers consisting of 3 and 4, this sequence is:
3, 4, 33, 34, 43, 44, 333, 334, 343, 344, 433, 434 、......
For example, to find the 5th number, the output is 43.
This is a Zoho interview, the problem is not very difficult.
Looking closely at this sequence, you can see that each number consists of 3 or 4, and we can group this sequence by the number of digits:
The first group is just one digit: 3,4
The second group is a number with only two digits: 33,34,43,44
The third group is a number with only three digits: 333, 334, 343, 344, 433, 434, 443, 444
.......
A closer look at each group, you can see, each group is a regular, nonsense, there must be regularity.
Replace each group of 3 with 0, 4 with 1 instead, then
The first group is: 0,1
The second group is: 00,01,10,11
The third group is: 000,001,010,011,100,101,110,111
So as long as you know the number of requirements is the first few groups on the line, to turn the required n into
n = 2^i + A
find that I and a,i are bits, that is, group I, A is the first group of a (a can be 0)
Then turn a into binary, for this binary, 0 with 3 instead, 1 on the 4 instead, the solution of the problem.
There are other solutions in Geeksforgeeks.
Find n ' th number in a number system with only 3 and 4