题目链接

题目大意就是这个,先找出下标的循环节,再快速幂对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. [译]Mongoose指南 - 查询

    查询有带callback和不带callback两种方式 所有mongoose的callback都是这种格式: callback(err, result) var Person = mongoose.m ...

  2. Ruby类的创建与使用

    Ruby是一种面向对象编程语言,这意味着它操纵的编程结构称为"对象" 先上代码, 了解类的定义与使用方式 class Computer $manufacturer = " ...

  3. 如何给wordpress外部链接自动添加nofollow

    wordpress多作者博客可以丰富网站的内容,但同时也会产生一些无关的链接,例如有些投机的人会考虑在文章中随意添加外部链接,如果你不想给这些外部链接传递权重,你需要给这些外部链接加上 rel=&qu ...

  4. 《深入浅出WPF》笔记二

    1.消息驱动与事件驱动 事件 即封装过的消息 2.数据驱动 3.Binding Source.Target.Path.INotifyPropertyChanged结构 this.textBoxName ...

  5. CentOS-6.5安装zabbix2.4.4

    使用epel源  (检查网络连接是否正常)   //这里使用epel源 [root@localhost /]# wget -O /etc/yum.repos.d/CentOS-Base.repo ht ...

  6. input注意事项

    一.更改place-holder颜色 input::-webkit-input-placeholder { color: #D6D0CA !important; /* WebKit browsers ...

  7. 正则表达式30分钟入门:http://deerchao.net/tutorials/regex/regex.htm#mission

    http://deerchao.net/tutorials/regex/regex.htm#mission

  8. Android之NetworkOnMainThreadException异常

    看名字就应该知道,是网络请求在MainThread中产生的异常 先来看一下官网的解释: Class Overview The exception that is thrown when an appl ...

  9. 160809209_李梦鑫_C语言程序设计实验2+选择结构程序设计_进阶

    <C语言程序设计>实验报告 学 号 160809209 姓 名 李梦鑫 专业.班 计科16-2班 学    期 2016-2017 第1学期 指导教师 黄俊莲 吴喆 实验地点 C05 机 ...

  10. cvLoadImage

    编辑 本词条缺少名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧! 函数原型:IplImage* cvLoadImage( const char* filename, int flags= ...