아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Crazy Malvika discovers Crazy Fibonacci function

시간 제한1초메모리 제한1024 MB

요약
f(1)=A, f(2)=B이고 f(x) = f(x-1) + f(x+1)인 수열에서 f(N)을 1e9+7로 나눈 나머지를 구한다.
난이도

보통10점 중 4점

유형
수학, 동적 계획법, 배열
정답자
아직 제출이 없습니다

문제

Malvika was getting bored of the usual Fibonacci problems, and decided to add a little twist to it. She defined a new function f() with the following properties:

  • She'll give you two integers, A and B. f(1) is defined to be A and f(2) is B.
  • And for all integers x ≥ 2, f(x) = f(x-1) + f(x+1).

She'll give an integer N, and you have to find out what f(N) is. Output the answers modulo 109+7.

입력

The first line of input contains a single integer T denoting number of test cases.

The only line of each test case contains three integers: A, B and N, denoting f(1), f(2) and the query.

출력

For each test case, output a line which contains a single integer, corresponding to f(N) for the given input.

제한

  • 1 ≤ T ≤ 105
  • -109 ≤ A , B ≤ 109
  • 1 ≤ N ≤ 109

힌트

In the first test case, f(3) = 7, and so that is the output.

In the second test case, f(3) = -6 and the answer modulo 109+7 is 1000000001.

예제1

  1. 예제 1

    입력
    2
    10 17 3
    23 17 3
    
    예상 출력
    7
    1000000001