SOLVE

LATER

Find the term

Problem

Editorial

Analytics

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$$**

Explanation

In Test case 1:

**$$K_3 = K_1 - K_2 = 4 - 2 = 2$$**

Time Limit:
1.0 sec(s)
for each input file.

Memory Limit:
256 MB

Source Limit:
1024 KB

Marking Scheme:
Marks are awarded when all the testcases pass.

Allowed Languages:
C,
C++,
Clojure,
C#,
D,
Erlang,
F#,
Go,
Groovy,
Haskell,
Java,
Java 8,
JavaScript(Rhino),
JavaScript(Node.js),
Lisp,
Lisp (SBCL),
Lua,
Objective-C,
OCaml,
Octave,
Pascal,
Perl,
PHP,
Python,
Python 3,
R(RScript),
Racket,
Ruby,
Rust,
Scala,
Scala 2.11.8,
Swift,
Visual Basic

Initializing Code Editor...

{"58a6755": "/pagelets/suggested-problems/algorithm/find-the-term-44/", "58a6997": "/pagelets/problems-hint/algorithm/find-the-term-44/", "58a6715": "/pagelets/show-submission/algorithm/find-the-term-44/", "58a69ae": "/pagelets/recommended-problems/algorithm/find-the-term-44/", "58a6977": "/pagelets/problem-author-tester/algorithm/find-the-term-44/"}

{}

realtime.hackerearth.com

80

c8c503bff2091e74238c09b32dde8553f7a96168

58a29e5cae2309f04b28

/realtime/pusher/auth/