1192 : Big Matrix
Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 933 Solved: 302Description
Given two matrices A
and B
with the same
size n × n, and
parameters a1, a2, b1, b2,
the two matrices are defined as:
- A(i,j) = i × a1 + j × a2
- B(i,j) = i × b1 + j × b2
where i, j are 0, 1, 2, ⋯, n − 1.
Calculate the sum of all elements of C = AB.
Input
No more than 10
test cases. For each case, n a1 a2 b1 b2 are given.
- 1 ≤ n ≤ 1000
- 1 ≤ a1, a2, b1, b2 ≤ 105
Output
The sum mod by 109 + 7.
Sample
2 1 1 1 1 4 1 2 3 4
10 3504
Hint
Author
CSGrandeur