forked from RyanFehr/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
37 lines (29 loc) · 1.1 KB
/
Solution.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
//Problem: https://www.hackerrank.com/challenges/fibonacci-modified
//Java 8
/*
{0,1,1,2,5,27,...}
Xi + (Xi+1)^2 = Xi+2
*/
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner input = new Scanner(System.in);
BigInteger t1 = new BigInteger(Integer.toString(input.nextInt()));
BigInteger t2 = new BigInteger(Integer.toString(input.nextInt()));
BigInteger output = new BigInteger("0");
int n = input.nextInt();
if(n == 1){System.out.println(t1);}
if(n == 1){System.out.println(t2);}
for(int i = 2; i < n; i++)
{
output = t2.multiply(t2);
output = output.add(t1);
t1 = new BigInteger(t2.toString());
t2 = new BigInteger(output.toString());
}
System.out.println(output);
}
}