Reputation: 76
import java.io.*;
import java.util.*;
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 s= new Scanner(System.in);
int t1=s.nextInt();
int t2= s.nextInt();
int n= s.nextInt();
double arr[]= new double[20];
for(int i=0;i<20;i++){
arr[i]=-1;
}
arr[1]= t1;
arr[2]=t2;
if(arr[n]!=-1){
System.out.println((long)arr[n]);
}
else{
for(int i=3;i<=n;i++){
arr[i]= arr[i-2] + Math.pow(arr[i-1],2);
}
System.out.println((long)arr[n]);
}
}
}
This code is a modified Fibonacci series. I want to calculate the tenth digit in this sequence. But the result is very big I want to ask in which type I should cast the answer ? I have used long but it failed...please suggest any other type ...
Upvotes: 0
Views: 176