An Arc of Dream is a curve defined by following function: 

HDU 4686 Arc of Dream(矩阵快速幂构造)


where 
a 0 = A0 
a i = a i-1*AX+AY 
b 0 = B0 
b i = b i-1*BX+BY 
What is the value of AoD(N) modulo 1,000,000,007?

Input

There are multiple test cases. Process to the End of File. 
Each test case contains 7 nonnegative integers as follows: 

A0 AX AY 
B0 BX BY 
N is no more than 10 18, and all the other integers are no more than 2×10 9.

Output

For each test case, output AoD(N) modulo 1,000,000,007.

Sample Input

1
1 2 3
4 5 6
2
1 2 3
4 5 6
3
1 2 3
4 5 6

Sample Output

4
134
1902

怎么构造?

根据这些已知条件:

A(n)=A(n-1)+ai-1bi-1

ai*bi=ai-1*bi-1*AX*BX+ai-1*AX*BY+bi-1*AY*BX+AY*BY

a i = a i-1*AX+AY 

b i = b i-1*BX+BY 

A(n)=A(n-1)+ai*bi

构造矩阵:

HDU 4686 Arc of Dream(矩阵快速幂构造)

 

 

相关文章: