Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Announcement
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Matrix Power Series
Time Limit:3000MS  Memory Limit:131072K
Total Submit:952 Accepted:282

Description

Given a n ¡Á n matrix A and a positive integer k, find the sum S = A + A2 + A3 + ¡­ + Ak.

Input

The input contains exactly one test case. The first line of input contains three positive integers n (n ¡Ü 30), k (k ¡Ü 109) and m (m < 104). Then follow n lines each containing n nonnegative integers below 32,768, giving A¡¯s elements in row-major order.

Output

Output the elements of S modulo m in the same way as A is given.

Sample Input

2 2 4
0 1
1 1

Sample Output

1 2
2 3

Source
POJ Monthly--2007.06.03, Huang, Jinsong

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top


All Rights Reserved 2003-2006 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator