-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFibonacci_Modified.java
46 lines (46 loc) · 1.21 KB
/
Fibonacci_Modified.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.io.*;
import java.util.*;
import java.math.*;
public class Fibonacci_Modified
{
static int bn = 0;
static BigInteger result = BigInteger.valueOf(0);
static BigInteger bt1;
static BigInteger bt2;
static BigInteger modifiedFib(BigInteger t1, BigInteger t2)
{
return t1.add(t2.multiply(t2));
}
static void calculation(BigInteger t1, BigInteger t2)
{
bn--;
if (bn == 0) {
result = t1;
}
else
{
calculation(t2, modifiedFib(t1, t2));
}
}
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String s = in.nextLine();
String[] numbersString = s.split(" ");
int t1 = Integer.parseInt(numbersString[0]);
int t2 = Integer.parseInt(numbersString[1]);
int n = Integer.parseInt(numbersString[2]);
bt1 = BigInteger.valueOf(t1);
bt2 = BigInteger.valueOf(t2);
bn = n;
if (0 <= t1 && 0 <= t2 && t1 <= 2 && t2 <= 2)
{
if (3 <= n || n <= 20)
{
calculation(bt1, bt2);
}
}
System.out.println(result);
}
}
//Fibonacci_Modified.java