[luoguP1962] 斐波那契数列(矩阵快速幂)
解析详见julao博客连接 http://worldframe.top/2017/05/10/清单-数学方法-——-矩阵/
——代码
#include <cstdio>
#include <cstring>
#define LL long long LL n;
const int p = 1e9 + ; struct Matrix
{
LL a[][];
Matrix()
{
memset(a, , sizeof(a));
}
}; inline Matrix operator * (const Matrix x, const Matrix y)
{
Matrix ans;
int i, j, k;
for(i = ; i < ; i++)
for(j = ; j < ; j++)
for(k = ; k < ; k++)
ans.a[i][j] = (ans.a[i][j] + x.a[i][k] * y.a[k][j]) % p;
return ans;
} inline int pow(LL x)
{
Matrix ans, trs;
ans.a[][] = ans.a[][] = ;
trs.a[][] = trs.a[][] = trs.a[][] = ;
while(x)
{
if(x & ) ans = ans * trs;
trs = trs * trs;
x >>= ;
}
return ans.a[][];
} int main()
{
scanf("%lld", &n);
printf("%d\n", pow(n - ));
return ;
}
[luoguP1962] 斐波那契数列(矩阵快速幂)的更多相关文章
- HDU4549 M斐波那契数列 矩阵快速幂+欧拉函数+欧拉定理
M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Sub ...
- POJ3070 斐波那契数列 矩阵快速幂
题目链接:http://poj.org/problem?id=3070 题意就是让你求斐波那契数列,不过n非常大,只能用logn的矩阵快速幂来做了 刚学完矩阵快速幂刷的水题,POJ不能用万能头文件是真 ...
- hdu4549 M斐波那契数列 矩阵快速幂+快速幂
M斐波那契数列F[n]是一种整数数列,它的定义如下: F[0] = aF[1] = bF[n] = F[n-1] * F[n-2] ( n > 1 ) 现在给出a, b, n,你能求出F[n]的 ...
- 洛谷P1962 斐波那契数列(矩阵快速幂)
题目背景 大家都知道,斐波那契数列是满足如下性质的一个数列: • f(1) = 1 • f(2) = 1 • f(n) = f(n-1) + f(n-2) (n ≥ 2 且 n 为整数) 题目描述 请 ...
- 51nod1242 斐波那契数列 矩阵快速幂
1242 斐波那契数列的第N项 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 #include<stdio.h> #define mod 100000000 ...
- hdu 4549 M斐波那契数列 矩阵快速幂+欧拉定理
M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Problem ...
- POJ 3070 Fibonacci【斐波那契数列/矩阵快速幂】
Fibonacci Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17171 Accepted: 11999 Descr ...
- hdu 4549 M斐波拉契 (矩阵快速幂 + 费马小定理)
Problem DescriptionM斐波那契数列F[n]是一种整数数列,它的定义如下: F[0] = aF[1] = bF[n] = F[n-1] * F[n-2] ( n > 1 ) 现在 ...
- 洛谷- P1306 斐波那契公约数 - 矩阵快速幂 斐波那契性质
P1306 斐波那契公约数:https://www.luogu.org/problemnew/show/P1306 这道题目就是求第n项和第m项的斐波那契数字,然后让这两个数求GCD,输出答案的后8位 ...
- POJ 3070(求斐波那契数 矩阵快速幂)
题意就是求第 n 个斐波那契数. 由于时间和内存限制,显然不能直接暴力解或者打表,想到用矩阵快速幂的做法. 代码如下: #include <cstdio> using namespace ...
随机推荐
- Linux磁盘分区、格式化和挂载
一.查看磁盘使用 [root@iZ88rvassw1Z ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 40G .3G 3 ...
- Android SQLite(1)简单示例-增,删,改,查
1.主要核心类,Sqlite编程要继承SQLiteOpenHelper import android.content.Context; import android.database.sqlite.S ...
- shell 2 解析
---- shell 3 /home/oracle/utility/macro/call_autopurge_arch.sh Description: Call purge archive log f ...
- Spring日期格式初始化
原文链接地址 一.初始化参数绑定[一种日期格式] 配置步骤: ①:在applicationcontext.xml中只需要配置一个包扫描器即可 1 2 <!-- 包扫描器 --> ...
- AJPFX分析int 和integer的区别
int是java提供的8种原始数据类型之一.Java为每个原始类型提供了封装类,Integer是java为int提供的封装类.int的默认值为0,而Integer的默认值为null,即Integer可 ...
- tomcat 启动失败 和闪退 和 启动成功却没有页面显示
1.解压版tomcat 将tomcat解压至英文目录下, 在系统环境变量里面配置 JAVA_HOME 和CATALINA_HOME (就是tomcat的安装目录) 在path中配置 %CATALINA ...
- 本地连接批处理修改IP
例子: 本地连接修改IP netsh interface ip delete dns "本地连接" addr=allnetsh interface ip add dns " ...
- CFAN:Coarse-to-Fine Auto-Encoder Networks (CFAN) for Real-Time Face Alignment
作者:嫩芽33出处:http://www.cnblogs.com/nenya33/p/6801045.html 版权:本文版权归作者和博客园共有 转载:欢迎转载,但未经作者同意,必须保留此段声明:必须 ...
- Maven error in eclipse (pom.xml) : Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4
i wanna make web project using the Maven to import automatically all libraries that i need, so i cho ...
- ArrayList集合的特点和几种遍历方法
public class temp { public static void main(String[] args)throws Exception { ArrayList 在定义时长度为空 ,在新增 ...