## Sap Labs Interview Question for Senior Software Development Engineers

- 0of 0 votes

AnswersA Fibonacci sequence is defined recursively by:

- Manoj September 17, 2020 in India for Senior Software Engineer

F0 = 0

F1 = 1

Fn = Fn − 1 + Fn − 2, for integer n > 1.

One way of generalizing the Fibonacci sequence is by starting with any pair of numbers and extending to negative values of n.

Given two terms of a generalized Fibonacci sequence Fp and Fq, their positions p and q respectively and a position r, find Fr.

Input Format

The first line of the input contains an integer t denoting the number of test cases.

Each test case contains three lines.

First line of each test case contains two space separated integers p and Fp

Second line contains two space separated integers q and Fq

Third line contains an integer r

Output Format

For each test case, print Fr which is the term of the sequence at position r.

If Fr is not an integer, represent it as an irreducible fraction in the form a/b where b > 0.

Sample Input

0 1

6 13

10

3 65

6 315

-10

0 11

1 -6

2

9 36

15 646

-5

11 72

20 5473

6

Sample Output

89

4620

5

-1/4

13/2| Report Duplicate | Flag | PURGE

Sap Labs Senior Software Development Engineer Java

**Team:**Senior Software Engineer

**Country:**India

**Interview Type:**Written Test

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.