转移矩阵很容易求就是|0  1|,第一项是|0|

|1  1|             |1|

然后直接矩阵快速幂,要用到费马小定理 :假如p是质数,且gcd(a,p)=1,那么 a(p-1)≡1(mod p)。即:假如a是整数,p是质数,且a,p互质(即两者只有一个公约数1),那么a的(p-1)次方除以p的余数恒等于1(这东西贡献了我8次wa)

对矩阵进行取余的时候余mod-1,因为矩阵求出来是要当作幂的,就是a^b%p=a^(b%(p-1))%p

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=<<+,inf=0x3f3f3f3f; struct Node{
ll row,col;
ll a[N][N];
};
Node mul(Node x,Node y)
{
Node ans;
ans.row=x.row,ans.col=y.col;
memset(ans.a,,sizeof ans.a);
for(ll i=;i<x.row;i++)
for(ll j=;j<x.col;j++)
for(ll k=;k<y.col;k++)
ans.a[i][k]=(ans.a[i][k]+x.a[i][j]*y.a[j][k])%(mod-);
return ans;
}
Node quick_mul(Node x,ll n)
{
Node ans;
ans.row=x.row,ans.col=x.col;
memset(ans.a,,sizeof ans.a);
for(ll i=;i<ans.col;i++)ans.a[i][i]=;
while(n){
if(n&)ans=mul(ans,x);
x=mul(x,x);
n>>=;
}
return ans;
}
ll mmul(ll a,ll b)
{
ll ans=;
while(b){
if(b&)ans=ans*a%mod;
a=a*a%mod;
b>>=;
}
return ans%mod;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
// cout<<setiosflags(ios::fixed)<<setprecision(2);
ll x,y,n;
while(cin>>x>>y>>n){
if(n==)
{
cout<<x<<endl;
continue;
}
Node A;
A.row=,A.col=;
A.a[][]=,A.a[][]=;
A.a[][]=,A.a[][]=;
A=quick_mul(A,n-);
Node B;
B.row=,B.col=;
B.a[][]=,B.a[][]=;
B=mul(A,B);
ll ans=mmul(x,B.a[][])*mmul(y,B.a[][])%mod;
cout<<ans<<endl;
}
return ;
}

最新文章

  1. Unexpected end of file from server 服务器访问问题导致
  2. codeforces 练习
  3. [转]Amazon AWS亚马逊云服务免费一年VPS主机成功申请和使用方法
  4. 谷歌浏览器安装adblock广告屏蔽插件
  5. projecteuler Problem 8 Largest product in a series
  6. Hadoop之TaskInputOutputContext类
  7. 用block响应button的点击事件
  8. Nginx 教程的连载计划
  9. 数以百万计美元的融资YO是什么东东?
  10. iOS TableView的分割线
  11. Python2.7笔记——常用技术点汇总
  12. Mybatis中 collection 和 association 的区别
  13. 初遇sass的两个小问题
  14. golang 打包,交叉编译,压缩
  15. pymysql的使用与参数简要
  16. Django 框架 数据库操作
  17. 修改sepolicy后编译出现‘Error while expanding policy’【转】
  18. 无法访问 MemoryStream 的内部缓冲区
  19. Scipy
  20. DataTable,List,Dictonary互转,筛选及相关写法

热门文章

  1. Jenkins之pipeline流水线配置
  2. talib 中文文档(七):Overlap Studies Functions
  3. Python开发【模块】:torndb
  4. IP层网络安全协议(IPSec)技术原理图解——转载图片
  5. mysql中的多行查询结果合并成一个(转)
  6. tar命令解压时如何去除目录结构及其解压到指定目录 (--strip-components N)
  7. SpringData_JpaSpecificationExecutor接口
  8. smart基础
  9. vim7.4在Win8下的安装及简单配置
  10. poj1434 Fill the Cisterns!