Power
InterviewTime limit1sMemory limit1024 MB
For each column j, raise the first-row value a_j to the power j+1, add all these diagonal powers, and print the sum modulo m.
- Level
Easy3 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
The table has rows and columns. The first row holds positive integers. Each of the next rows holds the powers of the numbers in the first row, in order: the second power, the third power, and so on.
In the table below, . The rows hold the powers of 3, 5, 2, and 1 up to the fifth power.
Write a program power that adds the numbers on the diagonal (the bold cells) and prints the sum modulo . For the example with , the sum is 9 + 125 + 16 + 1 = 151. The remainder of 151 divided by 3 is 1, so the answer is 1.
Input
The first line contains the positive integers and . The second line contains the numbers of the first row, separated by spaces.
Output
Print the sum of the diagonal numbers modulo as a single integer.
Constraints
, . The numbers in the first row are positive integers less than 100000.