传送门

矩阵快速幂板题,写一道来练练手。

这一次在poj做题总算没忘了改万能库。

代码:

#include<iostream>
#include<cstdio>
#define mod 10000
#define A a[0][0]
#define B a[0][1]
#define C a[1][0]
#define D a[1][1]
using namespace std;
int n;
struct Matrix{int a[2][2];Matrix(){A=0,B=C=D=1;}};
inline Matrix operator*(Matrix a,Matrix b){
	Matrix ret;
	ret.A=(a.A*b.A+a.B*b.C)%mod;
	ret.B=(a.A*b.B+a.B*b.D)%mod;
	ret.C=(a.C*b.A+a.D*b.C)%mod;
	ret.D=(a.C*b.B+a.D*b.D)%mod;
	return ret;
}
inline int ksm(){
	if(n==0)return 0;
	if(n==1)return 1;
	n-=2;
	Matrix x,ret;
	while(n){
		if(n&1)ret=ret*x;
		x=x*x,n>>=1;
	}
	return ret.D;
}
int main(){
	while(scanf("%d",&n)&&~n)printf("%d\n",ksm());
	return 0;
}

2018.09.25 poj3070 Fibonacci(矩阵快速幂)的更多相关文章

  1. poj3070 Fibonacci 矩阵快速幂

    学了线代之后 终于明白了矩阵的乘法.. 于是 第一道矩阵快速幂.. 实在是太水了... 这差不多是个模板了 #include <cstdlib> #include <cstring& ...

  2. POJ3070:Fibonacci(矩阵快速幂模板题)

    http://poj.org/problem?id=3070 #include <iostream> #include <string.h> #include <stdl ...

  3. UVA - 10229 Modular Fibonacci 矩阵快速幂

                                 Modular Fibonacci The Fibonacci numbers (0, 1, 1, 2, 3, 5, 8, 13, 21, 3 ...

  4. poj 3070 Fibonacci (矩阵快速幂乘/模板)

    题意:给你一个n,输出Fibonacci (n)%10000的结果 思路:裸矩阵快速幂乘,直接套模板 代码: #include <cstdio> #include <cstring& ...

  5. poj 3070 Fibonacci 矩阵快速幂

    Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. F ...

  6. HDU 1588 Gauss Fibonacci(矩阵快速幂)

    Gauss Fibonacci Time Limit: 3000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others) ...

  7. POJ 3070 Fibonacci 矩阵快速幂模板

    Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18607   Accepted: 12920 Descr ...

  8. $loj$10222 佳佳的$Fibonacci$ 矩阵快速幂

    正解:矩阵快速幂 解题报告: 我永远喜欢loj! 一看到这个就应该能想到矩阵快速幂? 然后就考虑转移式,发现好像直接想不好想,,,主要的问题在于这个*$i$,就很不好搞$QAQ$ 其实不难想到,$\s ...

  9. POJ 3070 Fibonacci矩阵快速幂 --斐波那契

    题意: 求出斐波那契数列的第n项的后四位数字 思路:f[n]=f[n-1]+f[n-2]递推可得二阶行列式,求第n项则是这个矩阵的n次幂,所以有矩阵快速幂模板,二阶行列式相乘, sum[ i ] [ ...

随机推荐

  1. C# ADO.NET 封装的增删改查

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. MySQL命令行学习

    1.登录mysql 本地:mysql -u root -p, 回车后输入密码; 也可以p后不加空格,直接加密码.回车就登录了 远程:mysql -hxx.xx.xx.xx -u -pxxx 2.查看数 ...

  3. VBA 公式中使用相对位置

    .Cells(3, 4).FormulaR1C1 = "=sum(r[-" & a & "]c[0]:r[-3]c[" & b & ...

  4. 使用SendMessage进行进程间通信

    Imports System.Runtime.InteropServices Public Class Monitor <DllImport("user32.dll", Ch ...

  5. pyorient

    简介 pyorient是orientdb的python库 该库提供两种访问orientdb的方式:1.client 的方式 2.ogm 的方式(类似于ORM) 由于OGM 封装了client,且由于O ...

  6. 常用类一一MATH类一一两个静态常量PI 和E,一些数学函数。

    package test; public class MathTest { public static void main(String[] args) { System.out.println(Ma ...

  7. Ansible Galaxy

    命令行工具 ansible-galaxy命令与Ansible捆绑在一起,您可以使用它从Galaxy或直接从基于git的SCM安装角色. 您还可以使用它在Galaxy网站上创建新角色,删除角色或执行任务 ...

  8. $.ajax dataType设置为json 回调函数不执行

    请求方式如下: $.xpost = function (url, data) { return $.ajax({ url: url, type: "POST", dataType: ...

  9. HttpClient 超时时间

    setSoTimeout(MilSec):连接超时时间.如果在连接过程中有数据传输,超时时间重新计算. setConnectTimeout(MilSec):获取连接超时时间.如果该参数没有设置,那么默 ...

  10. Resume (Curriculum Vitae)

    The resume (Curriculum Vitae) is a selling tool outlining your skills and experience so an employer ...