(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 ...
随机推荐
- IEnumerable<> ICollection <> IList<> 区别
IEnumerable< ICollection < IList区别 public interface IEnumerable { IEnumerator GetEnumerator(); ...
- Linux 开机启动方式设置 inittab 详解,开机直接进入“命令行”模式
Linux下的 /etc/inittab 中的英文解释: This file describes how the INIT process should set up the system in a ...
- HDU 5071 Chat(2014鞍山赛区现场赛B题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 解题报告:一个管理聊天窗口的程序,一共有八种操作,然后要注意的就是Top操作只是把编号为u的窗口 ...
- HDU 4930 Fighting the Landlords(模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 解题报告:斗地主,加了一个四张可以带两张不一样的牌,也可以带一对,判断打出一手牌之后,如果对手没 ...
- 在framework中打包xib
废话不多说,直接上图 1.Copy Bundle Resources 中加入相关xib 2.这里是重点,调用的时候不能直接写 [[NSBundle mainBundle] loadNibNamed:@ ...
- [HDU3709]Balanced Number
[HDU3709]Balanced Number 试题描述 A balanced number is a non-negative integer that can be balanced if a ...
- git 教程(11)--从远程库克隆
上次我们讲了先有本地库,后有远程库的时候,如何关联远程库. 现在,假设我们从零开发,那么最好的方式是先创建远程库,然后,从远程库克隆. 首先,登陆GitHub,创建一个新的仓库,名字叫gitskill ...
- django rest framework 的url标签的问题
如何在模板中引用一个在rest framework中的url? urls.py from django.conf.urls import patterns, url from .views impor ...
- PHP+Hadoop实现数据统计分析
记一次完全独立完成的统计分析系统的搭建过程,主要用到了PHP+Hadoop+Hive+Thrift+Mysql实现 安装 Hadoop安装: http://www.powerxing.com/inst ...
- AutoMapper Getting started
AutoMapper 是什么? 为什么要用AutoMapper? 如何使用AutoMapper? 在什么地方配置AutoMapper? 如何测试my mappings? AutoMapper 是什么? ...