The \( n^{th}\) term of a mathematical series is described as follows:
\( K_{n} = K_{n-1} - K_{n+1}\)
You have to find the \(m^{th}\) term, given the first two terms \(K_{1}\) and \(K_{2}\) of the series.
Input format:
The first line contains T, which denotes the number of test cases, after which T test cases follow.
Each test case is made up of two lines. The first line contains \(K_{1}\) and \(K_{2}\), the first two terms of the series. The second line contains m, for which \(K_{m}\) has to be calculated.
Output format:
T lines each containing the value of \(K_{m}\) for the corresponding test case. Since the value of \(K_{m}\) can be large, print the value modulo \(10^9 +7\).
Input constraints:
\(1 \leq T \leq 10^5\)
\(1 \leq N \leq 2 \times 10^9\)
\(|K_1| \leq 10^9\)
\(|K_2| \leq 10^9\)
In Test case 1:
\(K_3 = K_1 - K_2 = 4 - 2 = 2\)
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor