Given a number N. The task is to find first N Iccanobif Numbers.
Iccanobif Numbers are similar to Fibonacci Numbers. The K-th Iccanobif number can be obtained by addition of previous two numbers after reversing their digits.
The first few Iccanobif Numbers are:
0, 1, 1, 2, 3, 5, 8, 13, 39, 124, 514, 836, …..
Input : N = 5 Output : 0 1 1 2 3 Input : N = 9 Output : 0 1 1 2 3 5 8 13 39 Explanation: Upto 8th term, adding previous two terms is required, as there is an only single digit. For 9th term, adding 31(reversing 8th term) and 8 will give 39.
Approach: The idea is to take the first two Iccanobif Numbers as first = 0 and second = 1. Now iterate using a demoPointer N-2 times and every time find reverse of the previous two numbers using the approach discussed in: Reversing digits of a number. Find the sum of the two reversed numbers and update the variables first and second accordingly.
Below is the implementation of above approach:
0 1 1 2 3 5 8 13 39 124 514 836
Note: For larger value of N, use numbers as string.
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.
- Program to find sum of first n natural numbers
- Program to find first N Fermat Numbers
- Program to print first n Fibonacci Numbers | Set 1
- Program for cube sum of first n natural numbers
- Program to print first N Prime numbers
- Program to print first N Stepping numbers
- Find m-th summation of first n natural numbers.
- Find the average of first N natural numbers
- Find the Product of first N Prime Numbers
- Find the sum of first N odd Fibonacci numbers
- Find maximum N such that the sum of square of first N natural numbers is not more than X
- Find the good permutation of first N natural numbers
- Find the number of sub arrays in the permutation of first N natural numbers such that their median is M
- Find permutation of first N natural numbers that satisfies the given condition
- Find prime numbers in the first half and second half of an array
- Find the XOR of first N Prime Numbers
- Find the permutation of first N natural numbers such that sum of i % Pi is maximum possible
- Find numbers which are multiples of first array and factors of second array
- Find all divisors of first N natural numbers
- Find the K-th Permutation Sequence of first N natural numbers