(2016弱校联盟十一专场10.5) F. Fibonacci of Fibonacci

题目大意就是这个,先找出下标的循环节,再快速幂对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的更多相关文章
- 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 ...
- 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 ...
- (2016弱校联盟十一专场10.3) D Parentheses
题目链接 把左括号看成A右括号看成B,推一下就行了.好久之前写的,推到最后发现是一个有规律的序列. #include <bits/stdc++.h> using namespace std ...
- (2016弱校联盟十一专场10.3) B.Help the Princess!
题目链接 宽搜一下就行. #include <iostream> #include<cstdio> #include<cstring> #include<qu ...
- (2016弱校联盟十一专场10.3) A.Best Matched Pair
题目链接 #include<cstdio> #include<cstring> #include<algorithm> #include<stack> ...
- 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> # ...
- 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem description In ICPCCamp, there ar ...
- (2016弱校联盟十一专场10.2) A.Nearest Neighbor Search
题目链接 水题,算一下就行. #include <bits/stdc++.h> using namespace std; typedef long long ll; ll x[],y[], ...
- (2016弱校联盟十一专场10.2) E.Coins
题目链接 很久之前写的了,好像是对拍打表过的,推一下就行了. #include <bits/stdc++.h> using namespace std; typedef long long ...
随机推荐
- VTK初学一,a_Vertex图形点的绘制
系统:Win8.1 QT版本:2.4.2,Mingw VTK版本:6.3 2. main.cpp #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #incl ...
- Windows Phone 8下 友盟社会化组件SDK的使用。
由于项目的需要,要将友盟的社会化组件SDK由0.9更新至2.0. 版本变化比较大. 1.很多类以及命名空间已经取消了. 如UmengSocialSDK.Net.Request命名空间, UmengSo ...
- 【PHP面向对象(OOP)编程入门教程】22.把对象串行化serialize()方法,__sleep()方法,__wakeup()方法
有时候需要把一个对象在网络上传输,为了方便传输,可以把整个对象转化为二进制串,等到达另一端时,再还原为原来的对象,这个过程称之为串行化(也叫序列化), 就像我们现在想把一辆汽车通过轮船运到美国去,因为 ...
- PHP函数preg_replace() 正则替换所有符合条件的字符串
PHP preg_replace() 正则替换,与JavaScript 正则替换不同,PHP preg_replace() 默认就是替换所有符号匹配条件的元素. preg_replace (正则表达式 ...
- CSS选择器的特殊性和LOVE HA
在CSS中当几个相同的选择器对同一个元素有不同的规则时,该怎么应用这些规则呢? 答案就是:CSS特殊性(CSS specificity) 选择器特殊性有选择器本身组成,特殊性由4个数值表述:0, 0, ...
- CSS相邻兄弟选择器
相邻兄弟选择器定义:选择紧接在另一个元素后的元素,而且两者有着相同的父元素. 代码一:<body> <h1>This is a heading.</h1> < ...
- 【转】JavaScript面向对象
http://www.cnblogs.com/dolphinX/p/4385862.html 理解对象 对象这个词如雷贯耳,同样出名的一句话:XXX语言中一切皆为对象! 对象究竟是什么?什么叫面向对象 ...
- Java序列化技术与Protobuff
http://www.cnblogs.com/fangfan/p/4094175.html http://www.cnblogs.com/fangfan/p/4094175.html 前言: Java ...
- opencv统计二值图黑白像素个数
#include "iostream" #include "queue" #include "Windows.h" #include < ...
- 9.5---括号是否有效(CC150)
leetcode原题: char temp ; Stack<Character> stack = new Stack<Character>();//error:Stack< ...