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

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

InputThere 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.OutputFor 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

|   AX   0   AXBY   AXBY  0  |

|   0   BX  AYBX    AYBX  0  |

{a[i-1]   b[i-1]   a[i-1]*b[i-1]  AoD[i-1]  1}* |   0   0   AXBX    AXBX   0  |  = {a[i]   b[i]   a[i]*b[i]  AoD[i]  1}

|    0   0     0          1     0    |

|  AY  BY   AYBY   AYBY   1   |

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<string>
using namespace std;
typedef unsigned long long LL;
#define MAXN 30
#define L 100006
#define MOD 1000000007
#define INF 1000000009
const double eps = 1e-;
/*
这个题目跟之前做的有一定区别,之前做的大多是表示一个序列的转移矩阵(用一列 列向量表示一个序列的几项)
而这个题给出了 an 的转移关系 bn的转移关系 要求 an*bn的前n项和
应当扩充列的范围(矩阵表达的含义增加)
【An Bn An*Bn Sum(n)】 转移关系是很好列的,剩下的就是矩阵快速幂
*/
LL n, a0, ax, ay, b0, bx, by;
struct Mat
{
LL a[][];
Mat()
{
memset(a, , sizeof(a));
}
Mat operator*(const Mat& rhs)
{
Mat ret;
for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
if(a[i][j])
{
for (int k = ; k < ; k++)
{
ret.a[i][k] = (ret.a[i][k] + a[i][j] * rhs.a[j][k]) % MOD;
}
}
}
}
return ret;
}
};
Mat fpow(Mat m, LL b)
{
Mat ans;
for (int i = ; i < ; i++)
ans.a[i][i] = ;
while (b != )
{
if (b & )
ans = m * ans;
m = m * m;
b = b / ;
}
return ans;
}
int main()
{
while (scanf("%lld", &n) != EOF)
{
scanf("%lld%lld%lld%lld%lld%lld", &a0, &ax, &ay, &b0, &bx, &by);
if (n == )
{
printf("0\n");
continue;
}
Mat M;
M.a[][] = ax%MOD, M.a[][] = ax%MOD*by%MOD, M.a[][] = ax%MOD*by%MOD;
M.a[][] = bx%MOD, M.a[][] = M.a[][] = bx%MOD*ay%MOD;
M.a[][] = M.a[][] = ax%MOD*bx%MOD;
M.a[][] = ;
M.a[][] = ay%MOD, M.a[][] = by%MOD, M.a[][] = M.a[][] = ay%MOD*by%MOD, M.a[][] = ;
if (n == )
printf("%lld\n", a0*b0%MOD);
else
{
M = fpow(M, n - );
LL ans = ;
ans = (ans + a0*M.a[][] % MOD) % MOD;
ans = (ans + b0*M.a[][] % MOD) % MOD;
ans = (ans + +a0%MOD*b0%MOD*M.a[][] % MOD) % MOD;
ans = (ans + a0%MOD*b0%MOD*M.a[][] % MOD) % MOD;
ans = (ans +M.a[][] % MOD) % MOD;
printf("%lld\n", ans);
}
}
}

S - Arc of Dream 矩阵快速幂的更多相关文章

  1. HDU4686 Arc of Dream 矩阵快速幂

    Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  2. HDU4686——Arc of Dream矩阵快速幂

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4686 题目大意: 已知a0=A0, ai=Ax*ai-1+Ay; b0=B0, bi=Bx*bi-1 ...

  3. hdu 4686 Arc of Dream(矩阵快速幂)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 其中a0 = A0ai = ai-1*AX+AYb0 = B0bi = bi-1*BX+BY ...

  4. HDU 4686 Arc of Dream 矩阵快速幂,线性同余 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=4686 当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂 Ai,Bi的递推式题目 ...

  5. hdu----(4686)Arc of Dream(矩阵快速幂)

    Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  6. HDU4686 Arc of Dream —— 矩阵快速幂

    题目链接:https://vjudge.net/problem/HDU-4686 Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memo ...

  7. HDOJ 4686 Arc of Dream 矩阵高速幂

    矩阵高速幂: 依据关系够建矩阵 , 高速幂解决. Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/ ...

  8. hdu 4686 Arc of Dream_矩阵快速幂

    题意:略 构造出矩阵就行了 |   AX   0    AXBY   AXBY       0  |                                                   ...

  9. hdu4686 Arc of Dream ——构造矩阵+快速幂

    link: http://acm.hdu.edu.cn/showproblem.php?pid=4686 构造出来的矩阵是这样的:根据题目的ai * bi = ……,可以发现 矩阵1 * 矩阵3 = ...

随机推荐

  1. 计算误差——ACM计算几何中的精度问题

    浮点数为何会有精度问题   占字节数 数值范围 十进制精度位数 float 4 -3.4e-38~3.4e38 6~7 double 8 -1.7e-308~1.7e308 14~15 如果内存不是很 ...

  2. BFS(两点搜索) FZOJ 2150 Fire Game

    题目传送门 题意:'#'表示草地,两个人在草地上点火,相邻的草地会烧起来,每烧一格等1秒,问最少要等几秒草地才烧完 分析:这题和UVA 11624 Fire!有点像,那题给定了两个点,这题两点不确定, ...

  3. Kafka~服务端几个常用的命令

    在Centos上安装和部署完成kafka之后,我们就可以向服务端推消息和消费它了,今天主要聊几个常用的命令,比建立topic,从broken显示所有topics列表,向broken发消息,从broke ...

  4. [译]Cookies Without Chocolate Chips

    Cookies Without Chocolate Chips In the HTTP sense, a cookie is a name with an associated value. A se ...

  5. java excel poi导入 过滤空行的方法 判断是否是空行

    private boolean isRowEmpty(Row row){ for (int c = row.getFirstCellNum(); c < row.getLastCellNum() ...

  6. FCC 基础JavaScript 练习3

    1.通过使用提供的变量参数:名词myNoun.形容词myAdjective.动词myVerb.副词myAdverb,来创建一个新的句子 result, function wordBlanks(myNo ...

  7. 360 你妈妈知道你跟Python存在兼容问题吗?

    最近在用Python2.7.6版本开发的的过程中发现了一个问题 提示:UnicodeDecodeError:'ascii' codec can't decode bytes 0xb0 刚开始以为是编码 ...

  8. js类型识别

    typeof总结: 可以识别标准类型(Null除外) 不能识别具体的对象类型(Function除外) Object.prototype.toString总结: 可以识别标准类型和内置对象类型 不能识别 ...

  9. HDU_1233_还是畅通工程

    还是畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  10. 音视频】5.ffmpeg命令分类与使用

    GT其实平时也有一些处理音视频的个人或者亲人需求,熟练使用ffmpeg之后也不要借助图示化软件,一个命令基本可以搞定 G: 熟练使用ffmpeg命令!T :不要死记硬背,看一遍,自己找下规律,敲一遍, ...