# Fibodiv Number in Java

A number N that can be split into parts f1 and f2, such that if we take f1 and f2 as the first two terms of a Fibonacci series, then one of the terms of the Fibonacci series is the number N itself. Let's understand it with the help of some examples.

Example 1:

N = 14

Here, the number 14 can be split into two parts, 1 and 4. So, the first two terms of the Fibonacci series are f1 = 1 and f2 = 4. Hence, the series becomes

1, 4, 5 (1 + 4), 9 (4 + 5), 14 (5 + 9), 23 (9 + 14)

The above series contains the number 14. Therefore, 14 is a fibodiv number.

Example 2:

N = 15

Here, the number 15 can be split into two parts, 1 and 5. So, the first two terms of the Fibonacci series are f1 = 1 and f2 = 5. Hence, the series becomes

1, 5, 6 (1 + 5), 11 (5 + 6), 17 (6 + 11), 28 (11 + 17)

The above series does not contain the number 15. Therefore, 15 is not a fibodiv number.

Example 3:

N = 1292

Here, the number 1292 can be split into two parts 129 and 2. So, the first two terms of the Fibonacci series are: f1 = 129 and f2 = 2. Hence, the series becomes

129, 2, 131 (129 + 2), 133 (2 + 131), 264 (131 + 133), 397 (133 + 264), 661 (264 + 397),

1058 (397 + 661), 1719

The above series does not contain the number 1291. Now, we split the 1292 into another two parts 12 and 92. So, the first two terms of the Fibonacci series are: f1 = 12 and f2 = 92. Hence, the series becomes

12, 92, 104 (12 + 92), 196 (92 + 104), 300 (104 + 196), 496 (196 + 300), 796 (300 + 496),

1292 (496 + 796). Therefore, 1292 is a Fibodiv number.

## Algorithm

Step 1: Take a number N.

Step 2: Divide the number into two parts, f1 and f2, respectively, such that when we f2 with f1, we get the number N.

For example: 59 can be divided as 5 (f1 = 5), and 9 (f2 = 9). When we append 9 with 5, we get the number 59.

Step 3: Treat f1 and f2 as the first two terms of a Fibonacci-like series.

Step 4: Compute the next term (say f3) by adding f1 and f2, and then update f1 and f2. F1 takes the value of f2, and f2 takes the value of f3.

Step 5: Repeat step 4 till the next term f3 exceeds the number N, or f3 becomes equal to N.

Step 6: If f3 is equal to N, then N is a Fibodiv number; otherwise, repeat step 2 for different values of f1 and f2 (see example 3). If the division of the number n for the unique value of f1 and f2 is not possible, then n is not a Fibodiv number.

## Fibodiv Number Java Program

Let's see the implementation of the tug of war problem using the algorithm mentioned above.

### Using Iteration

FileName: FibodivNumber.java

Output:

```14 is a Fibodiv number.
19 is a Fibodiv number.
28 is a Fibodiv number.
47 is a Fibodiv number.
61 is a Fibodiv number.
75 is a Fibodiv number.
```

### Using Recursion

FileName: FibodivNumber1.java

Output:

```14 is a Fibodiv number.
19 is a Fibodiv number.
28 is a Fibodiv number.
47 is a Fibodiv number.
61 is a Fibodiv number.
75 is a Fibodiv number.
```

## Help Others, Please Share   