分析:这道题有点丧病啊......斐波那契数列本来增长就快,n <= 10^100又套2层,看到题目就让人绝望.不过这种题目还是有套路的.首先求斐波那契数列肯定要用到矩阵快速幂,外层的f可以通过取模来变小,可是里面的f不能直接取模1e9+7.因为余数最多就1e9+7种,所以肯定有一个循环节,打表发现内层f的循环节是2000000016,x的循环节是(1e9+7)*3,在求得时候mod循环节长度就ok了.

关于斐波那契的一些套路要记住:用矩阵快速幂加速、有循环节......

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const long long mod = ;
const long long mod2 = mod * + ;
const long long mod3 = mod2 * ; typedef long long ll; int T, len, shu[];
char s[];
ll t; struct node
{
ll a[][];
node(){ memset(a, , sizeof(a)); }
}x, y; ll zhuanhuan()
{
ll res = ;
for (int i = ; i <= len; i++)
shu[i] = s[i] - '';
for (int i = ; i <= len; i++)
res = (res * + shu[i]) % mod3;
return res;
} node mul1(node x, node y)
{
node p;
memset(p.a, , sizeof(p.a));
for (int i = ; i <= ; i++)
for (int j = ; j <= ; j++)
for (int k = ; k <= ; k++)
p.a[i][j] = (p.a[i][j] + x.a[i][k] * y.a[k][j] % mod2) % mod2;
return p;
} node mul2(node x, node y)
{
node p;
memset(p.a, , sizeof(p.a));
for (int i = ; i <= ; i++)
for (int j = ; j <= ; j++)
for (int k = ; k <= ; k++)
p.a[i][j] = (p.a[i][j] + x.a[i][k] * y.a[k][j] % mod) % mod;
return p;
} ll qpow1(ll b)
{
x.a[][] = ;
x.a[][] = ;
y.a[][] = ;
y.a[][] = y.a[][] = y.a[][] = ;
while (b)
{
if (b & )
x = mul1(x, y);
y = mul1(y, y);
b >>= ;
}
return x.a[][];
} ll qpow2(ll b)
{
x.a[][] = ;
x.a[][] = ;
y.a[][] = ;
y.a[][] = y.a[][] = y.a[][] = ;
while (b)
{
if (b & )
x = mul2(x, y);
y = mul2(y, y);
b >>= ;
}
return x.a[][];
} int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%s", s + );
len = strlen(s + );
t = zhuanhuan();
t = qpow1(t);
printf("%lld\n", qpow2(t));
} return ;
}

最新文章

  1. Python os 标准库使用
  2. php课程---数组
  3. php 配置正确的时间
  4. Java SAX Parser
  5. [Stephen]关于Ext.net fileupload 的兼容性解决问题
  6. MyEclipse修改项目名称
  7. C++指向常量的指针和常指针
  8. Linux 删除目录与文件
  9. 关于.net导出数据到excel/word【占位符替换】
  10. MySQL数据库事务及其特性
  11. 2018-2019-2 网络对抗技术 20165311 Exp3 免杀原理与实践
  12. BZOJ 4196 软件包管理器
  13. Appium入门(4)__ Appium Client安装
  14. SAP Module Pool Program Learning Documentation——Commit Work and Update dtab
  15. c#语言---数据类型
  16. 【μ&#39;sic forever♪♪♪】μ&#39;s Final Love Live周年纪念
  17. Spring笔记①--helloworld
  18. leetCode 41.First Missing Positive (第一个丢失的正数) 解题思路和方法
  19. js 校验身份证号
  20. ServlertContext

热门文章

  1. 关于minSdkVersion=&quot;8&quot; 升级appcompat_v7包主题&quot;Theme.AppCompat.Light&quot;等不存在的问题
  2. rabbitmq实践笔记(一):安装、配置与使用初探
  3. File文件存储
  4. IOS 中使用token机制来验证用户的安全性
  5. 打包Scala jar 包的正确步骤
  6. Objective -C Categories
  7. Record these plug-ins of vscode
  8. SpringBoot 快速开发框架
  9. gifsicle for linux ----------gif 图像处理
  10. mysql8忘记登录密码时,修改密码方法