Arc of Dream
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 4473 Accepted Submission(s): 1392
Problem Description
An Arc of Dream is a curve defined by following function:
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?
![](http://acm.hdu.edu.cn/data/images/C463-1001-1.jpg)
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:
N
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.
Each test case contains 7 nonnegative integers as follows:
N
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
Author
Zejun Wu (watashi)
Source
Recommend
zhuyuanchen520 | We have carefully selected several similar problems for you:
6032
6031
6030
6029
6028
不难想到矩阵快速幂,然后构造的矩阵。首先
1.ai*bi=(ai-1*AX+AY)*(bi-1*BX+BY)展开就知道需要的是什么了。
2.然后要计算的值sum=ai-1*bi-1+ai*bi。然后ai*bi可以又上面的式子得到。
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
long long n;
long long a0,ax,ay;
long long b0,bx,by;
struct matrix
{
long long a[5][5];
matrix operator * (const matrix & y)const
{
matrix ans= {0};
for(int i=0; i<5; ++i)
for(int j=0; j<5; ++j)
{
for(int k=0; k<5; ++k)ans.a[i][j]+=(a[i][k]*y.a[k][j])%mod;
ans.a[i][j]%=mod;
}
return ans;
}
};
long long getAns(long long n)
{
matrix result = {1,0,0,0,0, 0,1,0,0,0, 0,0,1,0,0, 0,0,0,1,0, 0,0,0,0,1};
matrix base = {1,0,0,0,0, (ax*bx)%mod,(ax*bx)%mod,0,0,0, (bx*ay)%mod,(bx*ay)%mod,bx,0,0, (ax*by)%mod,(ax*by)%mod,0,ax,0, (ay*by)%mod,(ay*by)%mod,by,ay,1};
matrix ans= {(a0*b0)%mod,(a0*b0)%mod,b0,a0,1};
while(n)
{
if(n&1ll)result=result*base;
base=base*base;
n>>=1ll;
}
return (ans*result).a[0][0];
}
int main()
{
while(~scanf("%I64d",&n))
{
scanf("%I64d%I64d%I64d",&a0,&ax,&ay);
scanf("%I64d%I64d%I64d",&b0,&bx,&by);
if(!n)
{
puts("0");
}
else
printf("%I64d\n",getAns(n-1));
}
return 0;
}