Fibonacci Modified

We define a modified Fibonacci sequence using the following definition:
Given terms  and  where , term  is computed using the following relation:
For example, if  and ,
  • ,
  • ,
  • ,
  • and so on.
Given three integers, , and , compute and print the  term of a modified Fibonacci sequence.
Function Description
Complete the fibonacciModified function in the editor below. It must return the  number in the sequence.
fibonacciModified has the following parameter(s):
  • t1: an integer
  • t2: an integer
  • n: an integer


private static BigInteger getFebo(int t1, int t2, int n) {

System.out.println(t1+" "+t2+" "+n);
BigInteger [] arr = new BigInteger[n];
arr[0] = BigInteger.valueOf(t1);
arr[1] = BigInteger.valueOf(t2);
for(int i=2;i<n;i++) {
arr[i] = (arr[i-1].multiply(arr[i-1])).add(arr[i-2]);
}
System.out.println(Arrays.toString(arr));
return arr[n-1];
}




Post a Comment

Previous Post Next Post