Given a number N, the task is to print the sequence upto N. The sequence is : 1, 2, 4, 8, 16, 22, 26, 38, 62, 74, 102, 104, 108, 116, 122, 126, 138, 162 and so on… This sequence is known as Digit – Product – Sequence. In this series, we take every non zero digit of the number, multiply them and add the product to the number itself.
Input : N = 10 Output :1 2 4 8 16 22 26 38 62 74 Input : N = 7 Output :1 2 4 8 16 22 26
1 + (1 * 1) = 1 + 1 = 2 2 + (2 * 1) = 2 + 2 = 4 4 + (4 * 1) = 4 + 4 = 8 8 + (8 * 1) = 8 + 8 = 16 16 + (1 * 6) = 16 + 6 = 22 22 + (2 * 2) = 22 + 4 = 26 26 + (2 * 6) = 26 + 12 = 38 38 + (3 * 8) = 38 + 24 = 62 62 + (6 * 2) = 62 + 12 = 74 and so on...
1 2 4 8 16 22 26 38 62 74
This article is contributed by Ayush Saxena. 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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Nth term of a sequence formed by sum of current term with product of its largest and smallest digit
- Count Possible Decodings of a given Digit Sequence
- Product of N with its largest odd digit
- First digit in product of an array of numbers
- Maximum number with same digit factorial product
- Largest palindrome which is product of two N-digit numbers : Set 2
- Check if all sub-numbers have distinct Digit product
- Last digit of Product of two Large or Small numbers (a * b)
- Largest palindrome which is product of two n-digit numbers
- Check if the product of digit sum and its reverse equals the number or not
- Sum and Product of all even digit sum Nodes of a Singly Linked List
- Number formed by adding product of its max and min digit K times
- Check whether a number can be expressed as a product of single digit numbers
- Maximize product of digit sum of consecutive pairs in a subsequence of length K
- Maximum of sum and product of digits until number is reduced to a single digit
- Min steps to convert N-digit prime number into another by replacing a digit in each step
- Count of Numbers in Range where first digit is equal to last digit of the number
- Count of pairs (A, B) in range 1 to N such that last digit of A is equal to the first digit of B
- Count numbers in a range with digit sum divisible by K having first and last digit different
- Find the remainder when First digit of a number is divided by its Last digit
Improved By : Mithun Kumar