File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+ import java .math .*;
3
+ import java .security .*;
4
+ import java .text .*;
5
+ import java .util .*;
6
+ import java .util .concurrent .*;
7
+ import java .util .regex .*;
8
+
9
+ public class Solution {
10
+
11
+ static BigInteger fibonacciModified (int t1 , int t2 , int n ) {
12
+
13
+ BigInteger [] memo = new BigInteger [n ];
14
+
15
+ memo [0 ] = new BigInteger (String .valueOf (t1 ));
16
+ memo [1 ] = new BigInteger (String .valueOf (t2 ));
17
+
18
+ //O(n) space and time
19
+ for (int i = 2 ; i < n ; i ++) {
20
+ memo [i ] = memo [i -1 ].multiply (memo [i -1 ]).add (memo [i -2 ]);
21
+ }
22
+ return memo [n - 1 ];
23
+
24
+ }
25
+
26
+ private static final Scanner scanner = new Scanner (System .in );
27
+
28
+ public static void main (String [] args ) throws IOException {
29
+ BufferedWriter bufferedWriter = new BufferedWriter (new FileWriter (System .getenv ("OUTPUT_PATH" )));
30
+
31
+ String [] t1T2n = scanner .nextLine ().split (" " );
32
+
33
+ int t1 = Integer .parseInt (t1T2n [0 ]);
34
+
35
+ int t2 = Integer .parseInt (t1T2n [1 ]);
36
+
37
+ int n = Integer .parseInt (t1T2n [2 ]);
38
+
39
+ BigInteger result = fibonacciModified (t1 , t2 , n );
40
+
41
+ bufferedWriter .write (result .toString ());
42
+ bufferedWriter .newLine ();
43
+
44
+ bufferedWriter .close ();
45
+
46
+ scanner .close ();
47
+ }
48
+ }
You can’t perform that action at this time.
0 commit comments