You are viewing a single comment's thread. Return to all comments →
import java.util.Scanner; public class FibonacciModified { public static long fibonacciModified(int t1, int t2, int n) { if (n == 1) return t1; else if (n == 2) return t2; else { long[] fibSequence = new long[n]; fibSequence[0] = t1; fibSequence[1] = t2; for (int i = 2; i < n; ++i) { fibSequence[i] = fibSequence[i-2] + fibSequence[i-1] * fibSequence[i-1]; } return fibSequence[n-1]; } } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t1 = scanner.nextInt(); int t2 = scanner.nextInt(); int n = scanner.nextInt(); System.out.println(fibonacciModified(t1, t2, n)); scanner.close(); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Fibonacci Modified
You are viewing a single comment's thread. Return to all comments →