Arya and the matrix
Practice
4.5 (2 votes)
Inverse Modulo
Easy
Math
Problem
20% Success 139 Attempts 20 Points 0.7s Time Limit 256MB Memory 1024 KB Max Code

Arya is in a problem in the city, Braavos. She has to solve a problem given by the faceless man in order to get free from the city.

She has a matrix A of size 2x2. Initially, the elements of the matrix are:

a11 a12
a21     a22

In each iteration, she has to change the elements of the matrix A as follows:

a11(new) = a11 + (a11 + a22)

a12(new) = a12 + (a12 + a21)

a21(new) = a21 + (a21 + a12)

a22(new) = a22 + (a22 + a11)

She is neither good at programming nor at mathematics, so she needs your help.

You have given the number of iteration n. You have to tell the elements of A after nth iteration.

Since the numbers are very large, take modulo 10^9 + 7.

Input Format :

First line will contain t, number of testcases. Then the testcases follow.

Each testcase will contains an integer, n.

The next line will contain four space separated integers a11 a12 a22 a21.

Output Format :

For each test case, print space separated four values in the new line: a11 a12 a22 a21

Constraints :

  • 1 <= t <= 100000
  • 1 <= n <= 10^18
  • 1 <= a11, a12, a22, a21 <= 10^9

Subtasks:

#1 (20 pts): 1 <= t, n, a11, a12, a22, a21 <= 1000

#2 (80 pts): Original Constraints

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:20
1 votes
Tags:
Easy
Points:20
22 votes
Tags:
MathematicsModular arithmeticEasy
Points:20
30 votes
Tags:
Modular arithmeticad-hocNumber TheoryEasyMathematicsBrute-force search簡単