noip模拟赛 残
分析:这道题有点丧病啊......斐波那契数列本来增长就快,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 ;
}
noip模拟赛 残的更多相关文章
- NOIP模拟赛20161022
NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程
数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
- 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...
- 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...
- CH Round #58 - OrzCC杯noip模拟赛day2
A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...
- CH Round #52 - Thinking Bear #1 (NOIP模拟赛)
A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...
随机推荐
- Android偏好设置(4)设置默认值
Setting Default Values The preferences you create probably define some important behaviors for your ...
- URAL1326. Bottle Taps(状压)
1326 用队列优化的 不知道为什么一直WA 传统直白的 状压 写了超时 O((1<<n)*m*n) 之后想了可以把n省去 预处理一下方案 #include <iostream&g ...
- redis 远程连接方法
解决方法 1.修改redis服务器的配置文件 vi redis.conf 注释以下绑定的主机地址 # bind 127.0.0.1 或 vim redis.conf bind 0.0.0.0 pr ...
- android环境搭建环境 cordova run android gradle wrapper报错
cordova run android命令报错 Error: Could not find an installed version of Gradle either in Android Studi ...
- Android基础夯实--重温动画(五)之属性动画 ObjectAnimator详解
只有一种真正的英雄主义 一.摘要 ObjectAnimator是ValueAnimator的子类,它和ValueAnimator一样,同样具有计算属性值的功能,但对比ValueAnimator,它会更 ...
- 临时笔记 Protection
如果操作系统不使用处理器的多任务机制,它仍然需要为栈创建至少一个TSS 当程序通过调用门改变特权级的时候,处理器执行下面的步骤切换栈,并且执行被调用的程序在新的特权级 1. 使用目标代码段的DPL从T ...
- [转帖]4412开发板/4418开发板Android4.4.4实现ble功能
本文转自迅为论坛:http://bbs.topeetboard.com ①.4418开发板实现ble功能方法: 在4418/android/device/nexell/drone2/device.mk ...
- Beta冲刺提交-星期三
- 这个作业属于哪个课程 <https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1> 这个作业要求在哪里 <htt ...
- bash - GNU Bourne-Again SHell
概述(SYNOPSIS) bash [options] [file] 版权所有(COPYRIGHT) Bash is Copyright (C) 1989-2002 by the Free Softw ...
- c++ 数组长度
数组长度求解 sizeof template <class T>int getArrayLen(T &array){ return (sizeof(array) / sizeof( ...