Crazy Malvika discovers Crazy Fibonacci function
InterviewTime limit1sMemory limit1024 MB
Given f(1)=A, f(2)=B, and f(x)=f(x-1)+f(x+1), find f(N) modulo 10^9+7 for up to 10^5 queries.
- Level
Medium4 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Malvika was getting bored of the usual Fibonacci problems, so she added a twist. She defined a new function f() with these properties:
- You are given two integers, A and B. f(1) is A and f(2) is B.
- For every integer x ≥ 2, f(x) = f(x-1) + f(x+1).
You are given an integer N. Find f(N). Output the answer modulo .
Input
The first line contains a single integer T, the number of test cases.
Each test case is one line with three integers A, B, and N, where A is f(1), B is f(2), and N is the query.
Output
For each test case, print one line containing f(N).
Constraints
Hint
In the first test case, f(3) = 7, so that is the output.
In the second test case, f(3) = -6, and the answer modulo is 1000000001.