# Iccanobif Number in Java

The Iccanobif number, also known as the "I-number," is a fascinating concept in the realm of mathematics. Although it might not be a term widely recognized it has gained attention among enthusiasts due to its unique properties and intriguing patterns. In the context of Java programming, understanding the Iccanobif number can be an exciting exploration.

The Iccanobif is the reverse of the word "Fibonacci," exhibit a fascinating pattern. The initial two Iccanobif numbers are defined as 0 and 1, just like the Fibonacci sequence.

Thus,

I(0)=0.

I(1)=1.

I(2)=I(1)+I(0)=1+0=1.

I(3)=I(2)+I(1)=1+1=2.

I(4)=I(3)+I(2)=2+1=3.

I(5)=I(4)+I(3)=3+2=5.

I(6)=I(5)+I(4)=5+3=8.

I(7)=I(6)+I(5)=8+5=13.

Up to this point, the Iccanobif numbers are exactly the same as the Fibonacci numbers. However, starting from I(8), the Iccanobif numbers deviate from the Fibonacci sequence.

I(8)=reverse(I(7))+I(6)=reverse(13)+8=31+8=39.

I(9)=reverse(I(8))+reverse(I(7))=reverse(39)+reverse(13)=93+31=124.

The reverse() method is used to reverse the digits of a number. However, for I(0) to I(7), which are single-digit numbers, reversing the digits has no effect since the reverse of a single-digit number is the number itself.

Therefore, the Iccanobif number series is :

0,1,1,2,3,5,8,13,39,124, ...

From the number 39 onwards, the Iccanobif numbers differ from the corresponding Fibonacci numbers. This distinction is why the number 39 has been highlighted. The Iccanobif sequence showcases an intriguing alteration in the pattern, adding an extra layer of fascination to this numerical exploration.

## Approach: Using Iterative

### ALGORITHM:

Step 1: Start with the given number 'n' representing the count of Iccanobif numbers to generate.

Step 2: Create two arrays, fib and rev, to store the Fibonacci numbers and reversed Fibonacci numbers, respectively.

Step 3: Set the base cases: fib[0]=0 and fib[1]=1.

Step 4: Use a loop to generate Fibonacci numbers from index 2 up to 'n'. The sum of the two Fibonacci numbers before it determines the next Fibonacci number.

Step 5: Use another loop to reverse the digits of each Fibonacci number and store the reversed numbers in the rev array.

Step 6: Calculate the Iccanobif number using the formula: iccanobif = rev[n] + rev[n - 1].

Step 7: Return the calculated Iccanobif number.

Step 8: Print the generated Iccanobif numbers.

Implementation:

The implementation of the above steps are given below

FileName: IccanobifNumbers.java

```import java.util.*;
public class IccanobifNumbers
{
public static void main(String[] args)
{
int n = 10; // Number of Iccanobif numbers to generate
// Generate and print the Iccanobif numbers
System.out.println("Iccanobif Numbers:");
for (int i=0;i<n;i++)
{
int number=generateIccanobif(i);
System.out.print(number+" ");
}
}
public static int generateIccanobif(int n)
{
if (n<=1) {
return n; // Base case: I(0) = 0, I(1) = 1
}
if (n<=7) {
return generateFibonacci(n); // Fibonacci numbers from I(0) to I(7) are the same
}
// Calculate Iccanobif number using iterative approach
int a=0;
int b=1;
int iccanobif=0;
for (int i=2;i<=n;i++)
{
iccanobif=reverseDigits(a)+reverseDigits(b);
a=b;
b=iccanobif;
}
return iccanobif;
}
public static int generateFibonacci(int n)
{
if (n <= 1) {
return n; // Base case: F(0) = 0, F(1) = 1
}
int a = 0;
int b = 1;
int fib = 0;
// Generate Fibonacci numbers iteratively
for (int i=2;i<=n;i++)
{
fib=a+b;
a=b;
b=fib;
}
return fib;
}
public static int reverseDigits(int num)
{
if (num<10)
{
return num; // Base case: Single digit number
}
int reversed=0;
while (num!=0)
{
int digit=num%10;
reversed=reversed*10+digit;
num/=10;
}
return reversed;
}
}
```

Output:

```Iccanobif Numbers:
0 1 1 2 3 5 8 13 39 124
```

### Complexity Analysis:

Time Complexity: The time complexity of this iterative approach is O(n), where 'n' is the count of Iccanobif numbers to generate. Generating the Fibonacci numbers and reversing the digits both take linear time.

Space Complexity: The space complexity is O(n) as we need to store 'n' Fibonacci numbers and 'n' reversed numbers in the arrays fib and rev, respectively.

## Approach 2: Using Recursion

### ALGORITHM

Step 1: Start with the given number 'n' representing the count of Iccanobif numbers to generate.

Step 2: Use a loop to generate Iccanobif numbers by making recursive calls.

Step 3: In each recursive call, calculate the Iccanobif number by adding the reversed digits of the (n-1)th and (n-2)th Fibonacci numbers.

Step 4: Implement a separate recursive function to generate Fibonacci numbers using the same recursive approach.

Step 5: Use another recursive function to reverse the digits of a given number.

Step 6: Implement appropriate base cases for both recursive functions to handle the initial conditions and single-digit numbers.

Step 7: Print the generated Iccanobif numbers.

Implementation:

The implementation of the above steps are given below

FileName: IccanobifNumbers.java

```import java.util.*;
public class IccanobifNumbers
{
public static void main(String[] args)
{
int n = 10; // Number of Iccanobif numbers to generate
// Generate and print the Iccanobif numbers
System.out.println("Iccanobif Numbers:");
for (int i=0;i<n;i++)
{
int number=generateIccanobif(i);
System.out.print(number+" ");
}
}
public static int generateIccanobif(int n)
{
if (n<=1)
{
return n; // Base case: I(0) = 0, I(1) = 1
}
if (n<=7)
{
return generateFibonacci(n); // Fibonacci numbers from I(0) to I(7) are the same
}
// Calculate Iccanobif number using recursive calls
int iccanobif=reverseDigits(generateIccanobif(n-1))+reverseDigits(generateIccanobif(n - 2));
return iccanobif;
}
public static int generateFibonacci(int n)
{
if (n<=1)
{
return n; // Base case: F(0) = 0, F(1) = 1
}
// Recursive call to generate Fibonacci numbers
return generateFibonacci(n-1)+generateFibonacci(n-2);
}
public static int reverseDigits(int num) {
if (num<10)
{
return num; // Base case: Single digit number
}
int reversed=0;
while (num!=0)
{
int digit=num%10;
reversed=reversed*10+digit;
num/=10;
}
return reversed;
}
}
```

Output:

```Iccanobif Numbers:
0 1 1 2 3 5 8 13 39 124
```

### Complexity Analysis:

Time Complexity: The time complexity of this recursive approach is exponential, O(2^n). Each recursive call generates two additional recursive calls, resulting in exponential growth.

Space Complexity: The space complexity is O(n) due to the recursion stack. The maximum depth of the recursion is 'n' when generating Iccanobif numbers, resulting in O(n) space usage.

Note 1: While doing the complexity analysis, we have assumed that the reversing digits of a number take O(1), i.e., constant time.

Note 2: For reversing the digits, one may take the help of the reverse() method of the StringBuilder class. However, before doing that, it is required to convert the numbers into Strings.