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 email@example.com. 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.
- Count of N-digit numbers having digit XOR as single digit
- 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
- Count 'd' digit positive integers with 0 as a digit
- Check if frequency of each digit is less than the digit
- Count n digit numbers not having a particular digit
- Generate a number such that the frequency of each digit is digit times the frequency in given number
- Largest number less than N with digit sum greater than the digit sum of N
- 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
- Count of pairs (A, B) in range 1 to N such that last digit of A is equal to the first digit of B
- Last digit of a number raised to last digit of N factorial
- 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
- Length of smallest sequence having sum X and product Y
- Largest palindrome which is product of two n-digit numbers
- First digit in product of an array of numbers
- Check whether a number can be expressed as a product of single digit numbers
- Check if the product of digit sum and its reverse equals the number or not
- Maximum of sum and product of digits until number is reduced to a single digit
Improved By : Mithun Kumar