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. ToolBar教程:AppCompatActivity下用toolbar当actionbar用

    参考: https://developer.android.com/training/appbar/index.html 1,自定义toolbar主题 2,在布局xml中使用toolbar 3,在代码 ...

  2. 论tab切换的几种实现方法

    tab切换在网页中很常见,故最近总结了4种实现方法. 首先,写出tab的框架,加上最简单的样式,代码如下: <!DOCTYPE html> <html> <head> ...

  3. Sql2008事务日志已满处理

    处理方式: USE [master] GO ALTER DATABASE gzl SET RECOVERY SIMPLE WITH NO_WAIT GO ALTER DATABASE gzl SET ...

  4. Android 将Bitmap对象保存为png图片文件

    输入:Bitmap对象.保存的路径.保存的文件名 注意路径的最后要带上  '/' 符号 private void saveBitmap(Bitmap bitmap,String path, Strin ...

  5. MySQL的基本概念与操作

    数据库的基本概念什么是数据库?用于存储和管理数据的仓库.数据库的特点:持久化存储数据的.其实数据库就是一个文件系统方便存储和管理数据使用了统一的方式操作数据库 – SQL数据库的分类:数据库根据存储采 ...

  6. Vue核心知识-computed和watch的使用场景和方法

    https://www.jianshu.com/p/bb7a2244c7ca

  7. CAD制作简单动画

    主要用到函数说明: IMxDrawEntity::Rotate 旋转一个对象.详细说明如下: 参数 说明 [in] IMxDrawPoint* basePoint 旋转基点 [in] DOUBLE d ...

  8. Linux下查看CPU信息、机器型号等硬件信息命令

    Linux下查看CPU信息.机器型号等硬件信息命令 编写一个bash脚本: vim info.sh #!/bin/bash cat /etc/issue echo "____________ ...

  9. thymeleaf在开发环境正常,但用jar运行时报错 Error resolving template template might not exist or might not be accessible

    解决方案: (1)配置中添加  spring.thymeleaf.prefix=classpath:/templates (2)指向模板的路径 不加 /

  10. block教程

    http://pernghh.pixnet.net/blog/trackback/eac87d412e/33563409 本文来自台湾的某开发人员的博客,被墙,感觉讲的比较易懂,所以引过来.文字简体化 ...