题意:输入N,输出fib(2^N)%1125899839733759。(P=1125899839733759是素数)

思路:欧拉降幂,因为可以表示为矩阵乘法,2^N在幂的位置,矩阵乘法也可以降幂,所以有ans=a*base^num; num=2^N%(P-1)。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll Mod=;
inline ll mul(ll x,ll y,ll p){
return ((x*y-(ll)(((long double)x*y+0.5)/p)*p)%p+p)%p;
}
struct mat
{
ll M[][];
mat() { memset(M,,sizeof(M)); }
mat friend operator *(mat a,mat b)
{
mat res;
for(int k=;k<=;k++)
for(int i=;i<=;i++)
for(int j=;j<=;j++)
res.M[i][j]=(res.M[i][j]+mul(a.M[i][k],b.M[k][j],Mod))%Mod;
return res;
}
mat friend operator ^(mat a,ll x)
{
mat res; res.M[][]=res.M[][]=1LL;
while(x){
if(x&1LL) res=res*a; a=a*a; x/=;
} return res;
}
};
ll qpow(ll a,ll x,ll p){
ll res=; while(x){
if(x&1LL) res=mul(res,a,p);
a=mul(a,a,p); x/=;
} return res;
}
int main()
{
int T; ll N,num;
scanf("%d",&T);
while(T--){
scanf("%lld",&N);
num=qpow(2LL,N,Mod-);
num--; if(num<) num+=Mod-;
mat base,a;
base.M[][]=base.M[][]=base.M[][]=1LL; a.M[][]=1LL;
base=base^num;
a=base*a;
printf("%lld\n",a.M[][]);
}
return ;
}

最新文章

  1. IntelliJ IDEA注册码
  2. Atom
  3. wpa_supplicant测试
  4. hdu 3804 树链剖分
  5. MongoDB(二)
  6. Python练习28
  7. 抛弃JQ,回归原生js……
  8. js构建函数优秀案例
  9. Ubuntu14.04安装pycharm用于Python开发环境部署,并且支持pycharm使用中文输入
  10. DLC 基本定律与规则
  11. java 打印乘法口诀表
  12. Delphi操作Ini文件
  13. 【python】xsspider零碎知识点
  14. zookeeper简单实战
  15. 使用 Azure CLI 创建 Linux 虚拟机
  16. android端的ormlite框架
  17. 认识单点登录cas
  18. PHP7.1中使用openssl替换mcrypt
  19. emailautocomplete
  20. IIS发布常见错误-HTTP 错误 404.0 - Not-Found

热门文章

  1. Groovy系列-groovy比起Java--有哪些地方写起来更舒服?
  2. JQuery 操作 checkbox 二次赋值无效 attr ----&gt; prop
  3. This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in问题
  4. (from) Javascript 生成指定范围数值随机数
  5. Linux:Ubuntu16.04下创建Wifi热点
  6. matlab fread
  7. hadoop06---多线程
  8. @MarkFan 口语练习录音 20140401
  9. classpath是什么
  10. B-树 C++模板类封装(有图有真相)