题目链接

题目大意就是这个,先找出下标的循环节,再快速幂对20160519取余就行了。

找出下标循环节:

#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int i=,a=,b=;
for(;;i++)
{
int t=b;
b=(a+b)%;
a=t%;
if(a==&&b==)
{
printf("%d\n",i);
break;
}
}
return ;
}

AC代码:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
typedef long long ll;
const ll mod=;
const ll mod2=;
int n,t;
ll ans_id,ans_x;
struct matrix
{
ll data[][];//必须ll
};
matrix I={,,,};//起始!
matrix a={,,,};//乘数!
matrix multi(matrix a,matrix b,ll mod)
{
matrix c;
memset(c.data,,sizeof(c.data));
for(int i=;i<;i++)
for(int j=;j<;j++)
for(int k=;k<;k++)
{
c.data[i][j]=c.data[i][j]+(a.data[i][k]%mod)*(b.data[k][j]%mod); //超过ll
c.data[i][j]%=mod;
}
return c;
}
long long pow(matrix a,int b,ll mod)
{
matrix ans=I;
while(b)
{
if(b&)
{
ans=multi(ans,a,mod);
b--;
}
b>>=;
a=multi(a,a,mod);
}
return ans.data[][];
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
ans_id=pow(a,n-,mod2);
ans_x=pow(a,ans_id-,mod);
printf("%lld\n",ans_x);
}
return ;
}

(2016弱校联盟十一专场10.5) F. Fibonacci of Fibonacci的更多相关文章

  1. 2016弱校联盟十一专场10.5---As Easy As Possible(倍增)

    题目链接 https://acm.bnu.edu.cn/v3/contest_show.php?cid=8506#problem/A problem description As we know, t ...

  2. 2016弱校联盟十一专场10.3---Similarity of Subtrees(深搜+hash、映射)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52310 problem description Define the depth of a ...

  3. (2016弱校联盟十一专场10.3) D Parentheses

    题目链接 把左括号看成A右括号看成B,推一下就行了.好久之前写的,推到最后发现是一个有规律的序列. #include <bits/stdc++.h> using namespace std ...

  4. (2016弱校联盟十一专场10.3) B.Help the Princess!

    题目链接 宽搜一下就行. #include <iostream> #include<cstdio> #include<cstring> #include<qu ...

  5. (2016弱校联盟十一专场10.3) A.Best Matched Pair

    题目链接 #include<cstdio> #include<cstring> #include<algorithm> #include<stack> ...

  6. 2016弱校联盟十一专场10.3---We don't wanna work!(STL--set的使用)

    题目链接 https://acm.bnu.edu.cn/v3/contest_show.php?cid=8504#problem/C 代码如下: #include <iostream> # ...

  7. 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem  description In ICPCCamp, there ar ...

  8. (2016弱校联盟十一专场10.2) A.Nearest Neighbor Search

    题目链接 水题,算一下就行. #include <bits/stdc++.h> using namespace std; typedef long long ll; ll x[],y[], ...

  9. (2016弱校联盟十一专场10.2) E.Coins

    题目链接 很久之前写的了,好像是对拍打表过的,推一下就行了. #include <bits/stdc++.h> using namespace std; typedef long long ...

随机推荐

  1. 设置二级域名共享一级域名Cookie和删除共享Cookie

     设置共享Cookie: 二级域名要想共享一级域名的cookie,只需要设置cookie.Domain = ".一级域名.com";   删除共享Cookie:  HttpCook ...

  2. putchar和puts

    #include<stdio.h> int main() { char a = 'h'; char b[] = "hello"; putchar(a); //putch ...

  3. 6.3.28微信需群主确认才可进群&发GIF动图功能内测开始了

    昨天下午有网友收到微信6.3.28新版内测邀请,不过这个内部体验目前貌似只对安卓手机开放,苹果的IOS系统还不支持,会提示“你当前使用的是非安卓设备,不建议下载安卓体验包,但你仍可邀请朋友尝鲜”.最新 ...

  4. Mac 上真正替换LiveWriter 的工具 - ecto

    Mac 上真正替换LiveWriter 的工具 - ecto 13年开始使用mac.而后想把 windows 替换到.一直在寻找LiveWriter 的工具,至今终于找到 我先感谢这位博主 http: ...

  5. Ping CAP CTO、Codis作者谈redis分布式解决方案和分布式KV存储

    此文根据[QCON高可用架构群]分享内容,由群内[编辑组]志愿整理,转发请注明出处. 苏东旭,Ping CAP CTO,Codis作者 开源项目Codis的co-author黄东旭,之前在豌豆荚从事i ...

  6. [Asp.net MVC]Asp.net MVC5系列——添加数据

    目录 概述 显示添加数据时所用表单 处理HTTP-POST 总结 系列文章 [Asp.net MVC]Asp.net MVC5系列——第一个项目 [Asp.net MVC]Asp.net MVC5系列 ...

  7. shareSDK

    一. 编写sharesdk代码 在AppDelegate.m中 //shareSDK相关 #import <ShareSDK/ShareSDK.h> #import "Weibo ...

  8. Linux之编译需要的文件变化时刻

  9. const 和宏的区别

    参考:http://blog.sina.com.cn/s/blog_79b01f6601018xdg.html (1) 编译器处理方式不同 define宏是在预处理阶段展开. const常量是编译运行 ...

  10. TP框架自动加载优先级

    $map = array('Think\Log'=>THINK_PATH.'Think\Log.php','Org\Util\Array'=>THINK_PATH.'Org\Util\Ar ...