I am trying to get the value for a `n`

-th series. such that `f(n)=2014*f(n-1) + 69*f(n-2)`

for `(n>2)`

and `f(n)=1`

for `n<=2`

. I am using `BigInteger`

as it is my requirement. While running code for smaller values I am getting answer. When `n`

exceeds such as 123 I am not getting the result. Any modification in code or way to shrink run the time??

```
public class test {
public static BigInteger FindSumDigit (BigInteger number) {
BigInteger one = new BigInteger("1");
BigInteger two = new BigInteger("2");
BigInteger result, zero = new BigInteger("0");
BigInteger a = new BigInteger("2014");
BigInteger b = new BigInteger("69");
if(number.equals(one))
return one;
else if (number.equals(two))
return one;
else
return a.multiply(FindSumDigit(number.subtract(one))).add(b.multiply(FindSumDigit(number.subtract(two)))); //finding the n-th element
}
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int N = s.nextInt();
BigInteger q[] = new BigInteger[N];
if(1 <= N && N < 10)
for(int i = 0; i < N; i++) {
BigInteger n = s.nextBigInteger();
BigInteger o = FindSumDigit(n);
System.out.println(o);
}
}
}
```

### More Related Questions

- How to avoid StackOverflowError caused by the number of recursion calls in Java? I want to solve this problem: https://www.hackerrank.com/challenges/find-median ,i.e. find the median element in unsorted array. To do this I perform quickselect algorithm. My program […]
- Binary Tree implementation using a recursive approach Project: "Create an implementation of a binary tree using the recursive approach introduced in the chapter. In this approach, each node is a binary tree. Thus a binary tree contains a […]
- Why does method change the boolean array parameter? I have a class for finding a path through a basic maze. A maze is passed to path along with starting and ending positions. I use recursion to find a path between the points. The path is […]
- return not returning an accurate value in C I had written this code which has the recursive function differ, when I run it, using the printf statements I notice that the code executes in the proper direction and I get the required […]
- Termination of mutually recursive functions using the Maybe monad Below is are two examples of mutually recursive function pairs. The first example terminates and produces the expected result. The second example is similar, except it uses the Maybe […]
- Determining the complexities given codes Given a snipplet of code, how will you determine the complexities in general. I find myself getting very confused with Big O questions. For example, a very simple question:
for (int i = […]
- How exactly does minimax recursion work? So I was looking up Mini-max for a Tic-Tac-Toe Game, but couldn't understand how the recursion worked? Okay, so basically here are my questions:
How does minimax know whose turn is it? […]
- hamiltonian Path of an Obstructed Grid and Python Recursion Limts I am attempting to find any Hamiltonian paths in a given grid, which contains obstacles at various nodes. My issue is that my code has been running for days now and has yet to come to an […]
- asp.net FindControl Recursively This is a really weird one - I will do my best to explain.
I have a basic master page:
<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="master_MasterPage" […]
- Get parents recursive in right order for deletion from MySQL table I have an table structure like this
mysql> SELECT id, name, parent_id FROM categories;
+-------+------------+-----------+
| id | name | parent_id […]