Summing Sums
Time limit1sMemory limit128 MB
Each round every cow replaces her number with the sum of the other cows' numbers mod 98765431; report the values after exactly T rounds.
- Level
Medium7 of 10
- Topics
- Math, Matrix, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
cows, numbered through , each start with an integer . Every round, all cows act simultaneously:
- Each cow computes the sum of the numbers held by the other cows.
- Once every cow has finished, each cow replaces her own number with the sum she just computed.
To keep the numbers from growing too large, every number is always kept modulo 98,765,431. After the round has been repeated exactly times, report the number held by each cow.
Constraints:
Input
- Line 1: two space-separated integers and .
- Lines 2 through : line contains the starting number of cow .
Output
- Print lines; line contains the number held by cow after the repetitions finish, taken modulo 98,765,431.
Hint
The table below shows the cows' numbers after each round for the example.
Cows' numbers
Round Cow1 Cow2 Cow3
0 1 0 4
1 4 5 1
2 6 5 9
3 14 15 11
4 26 25 29