Consider a series of numbers composed of only digits 4 and 7. The first few numbers in the series are 4, 7, 44, 47, 74, 77, 444, .. etc. Given a number constructed by 4, 7 digits only, we need to find the position of this number in this series.
Input : 7 Output : pos = 2 Input : 444 Output : pos = 7
It is reverse of the following article :
Find n-th element in a series with only 2 digits (4 and 7) allowed | Set 2 (log(n) method)
"" / \ 1(4) 2(7) / \ / \ 3(44) 4(47) 5(74) 6(77) / \ / \ / \ / \
The idea is based on the fact that all even positioned numbers have 7 as the last digit and all odd positioned numbers have 4 as the last digit.
If the number is 4 then it is the left node of the tree, then it corresponds to (pos*2)+1. Else right child node(7) corresponds to (pos*2)+2.
This article is contributed by Devanshu Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Position of n among the numbers made of 2, 3, 5 & 7
- Check if two strings can be made equal by swapping one character among each other
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
- Find two numbers made up of a given digit such that their difference is divisible by N
- Find maximum product of digits among numbers less than or equal to N
- Find maximum among x^(y^2) or y^(x^2) where x and y are given
- Check if given array can be made 0 with given operations performed any number of times
- Number of digits in the nth number made of given four digits
- Check if elements of array can be made equal by multiplying given prime numbers
- Count number of strings (made of R, G and B) using given combination
- Number of words that can be made using exactly P consonants and Q vowels from the given string
- Check if X and Y can be made zero by using given operation any number of times
- Repeated subtraction among two numbers
- Maximum LCM among all pairs (i, j) of first N natural numbers
- Maximum GCD among all pairs (i, j) of first N natural numbers
- Find the character made by adding all the characters of the given string
- Find the n-th number made of even digits only
- Largest number made up of X and Y with count of X divisible by Y and of Y by X
- Minimum and maximum number of N chocolates after distribution among K students
- N-th character in the string made by concatenating natural numbers