Find the term
Practice
0 (0 votes)
Mathematics
Hard
Approved
Recruit
Problem
1 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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\)

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
4 votes
Tags:
ImplementationGraphsAlgorithmsBrute ForceBreadth-first search
Points:50
Tags:
Medium-Hard
Points:20
34 votes
Tags:
Ad-HocAlgorithmsApprovedEasyOpen