TCS
Company
Programming
Matrix Power
Alice is learning basic discrete mathematics. In between of her leanings one day her tutor has given the following problem.
"A^M = A*A*A ... M times."
Let K be the matrix with N*N size and Aij represent the element at ith row and jth column. Matrix exponent product is defined as . As the result can be long mod the result with 1000000007.
As the Alice is newbie to maths, help her to solve the problem.
Input Format:
First line starts with N, and then N lines follow each will contain N spaced integers Aij.
After N lines next line contains M.
Output Format:
Print the matrix exponent product.
Constraints:
1<=N<=4000
1<=Aij<=10^7
1<=M<=10^9
Read Solution (Total 0)
TCS Other Question
Cliff and Radar
Two cliffs of lengths X and Y join at one end and enclose a body of water. The angle between the cliffs, phi, is known. A radar is installed at the point where the cliffs are joined. It has a range of m where m < X and m < Y. Calculate the area of the water enclosed between the cliffs which cannot be scanned by the radar and the distance between the end points of two cliffs.
Fig:Cliff and Radar
Input Format:
First line contains length of cliff AB, denoted by X in meters
Second line contains length of cliff AC, denoted by Y in meters
Third line contains range of radar, denoted by m in meters
Fourth line contains angle BAC in degrees, denoted by Φ (phi)
Output Format:
On first line, print the area enclosed between the cliffs that cannot be scanned by the radar in square meters
On second line, print the distance between end points of two cliffs in meters
Constraints:
X > 0
Y > 0
0 < m < X and 0 < m < Y
Φ (phi) > 0
Calculations should be done upto 11-digit precision, but output values should be printed upto 5 decimal places
Rotation
A Game developer is developing a game. To enrich his graphics he needs a quick API to do rotation and scaling of objects of various shapes that appear in the game. You have been chosen to partner this developer. Shoulder the responsibility of developing this API.
You have your work cut-out in form of the input and output specs below.
Input Format:
First line contains number of sides of a polygon, denoted by N
Next N lines contain x and y coordinates, respectively, of the points forming the polygon, delimited by space
Next line contains angle of rotation A
Next line contains scaling factor S
Last line contains coordinates about which the polygon has to be rotated, denoted by (a, b)
Output Format:
Print new coordinates of polygon after rotation and scaling
Constraints:
Polygon will be 3-sided or higher
x and y can be positive or negative integers or zero
Angle of rotation (A) can have only three discrete values {90, 180, 270} in degree
Positive angles indicate clock-wise rotation. Negative angles indicate anti clock-wise rotation
Scaling Factor S can be greater than 1
Point around which the polygon has to be rotated, denoted by (a, b) can be positive or negative integers or zero