题目链接:http://codeforces.com/problemset/problem/450/B

题意很好懂,矩阵快速幂模版题。

 /*
| 1, -1 | | fn |
| 1, 0 | | fn-1 |
*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef __int64 LL;
LL mod = 1e9 + ;
struct data {
LL mat[][];
}; data operator* (data a , data b) {
data res;
for(int i = ; i <= ; i++) {
for(int j = ; j <= ; j++) {
res.mat[i][j] = ;
for(int k = ; k <= ; k++) {
res.mat[i][j] = ((a.mat[i][k]*b.mat[k][j] % mod) + res.mat[i][j]) % mod;
}
}
}
return res;
} data operator^ (data a , LL n) {
data res;
for(int i = ; i <= ; i++) {
for(int j = ; j <= ; j++) {
res.mat[i][j] = (i == j);
}
}
while(n) {
if(n & )
res = a * res;
a = a * a;
n >>= ;
}
return res;
} int main()
{
data res;
LL n;
cin >> res.mat[][] >> res.mat[][] >> n;
if(n == ) {
cout << (res.mat[][] % mod + mod) % mod << endl;
}
else if(n == ) {
cout << (res.mat[][] % mod + mod) % mod << endl;
}
else {
data a;
a.mat[][] = a.mat[][] = ;
a.mat[][] = ;
a.mat[][] = -;
a = a ^ (n - );
res = a * res;
cout << (res.mat[][] % mod + mod) % mod << endl;
}
}

Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences (矩阵快速幂)的更多相关文章

  1. Codeforces Round #257(Div. 2) B. Jzzhu and Sequences(矩阵高速幂)

    题目链接:http://codeforces.com/problemset/problem/450/B B. Jzzhu and Sequences time limit per test 1 sec ...

  2. Codeforces Round #257 (Div. 2) B Jzzhu and Sequences

    Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...

  3. Codeforces Round #373 (Div. 2) E. Sasha and Array 矩阵快速幂+线段树

    E. Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input standard ...

  4. Codeforces 450B div.2 Jzzhu and Sequences 矩阵快速幂or规律

    Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...

  5. codeforces 450B B. Jzzhu and Sequences(矩阵快速幂)

    题目链接: B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input ...

  6. Codeforces Round #257 (Div. 2/B)/Codeforces450B_Jzzhu and Sequences

    B解题报告 算是规律题吧,,,x y z -x -y -z 注意的是假设数是小于0,要先对负数求模再加模再求模,不能直接加mod,可能还是负数 给我的戳代码跪了,,. #include <ios ...

  7. Codeforces Round #257 (Div. 1)449A - Jzzhu and Chocolate(贪婪、数学)

    主题链接:http://codeforces.com/problemset/problem/449/A ------------------------------------------------ ...

  8. Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)

    题目链接:http://codeforces.com/problemset/problem/450/A ------------------------------------------------ ...

  9. Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)

    题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...

随机推荐

  1. Ubuntu 64位系统安装StarUML之最佳实践

    preview 相信很多使用Ubuntu的哥们在安装StarUML或者其他软件时都会遇到要求libgcrypt11的依赖.而遗憾的时,这个东西很多人根本找不到. 我将它分享到百度网盘,mark. 一. ...

  2. hdu 4882 ZCC Loves Codefires (贪心 推导)

    题目链接 做题的时候凑的规律,其实可以 用式子推一下的. 题意:n对数,每对数有e,k, 按照题目的要求(可以看下面的Hint就明白了)求最小的值. 分析:假设现在总的是sum, 有两个e1 k1 e ...

  3. ACM - ICPC World Finals 2013 C Surely You Congest

    原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 试题来源 ACM/ICPC World Fin ...

  4. Vagrant工具

    Vagrant 是一款用来构建虚拟开发环境的工具,非常适合 php/python/ruby/java 这类语言开发 web 应用,“代码在我机子上运行没有问题”这种说辞将成为历史. 我们可以通过 Va ...

  5. Oracle 创建和使用视图

    一.what(什么是视图?) 1.视图是一种数据库对象,是从一个或者多个数据表或视图中导出的虚表,视图所对应的数据并不真正地存储在视图中,而是存储在所引用的数据表中,视图的结构和数据是对数据表进行查询 ...

  6. Mybatis拦截器介绍

    拦截器的一个作用就是我们可以拦截某些方法的调用,我们可以选择在这些被拦截的方法执行前后加上某些逻辑,也可以在执行这些被拦截的方法时执行自己的逻辑而不再执行被拦截的方法.Mybatis拦截器设计的一个初 ...

  7. bjfu1252 贪心

    题目意思是给出一些开区间,这些区间有的相交,有的不相交,问你能否选出一些区间,使这些区间之间都不相交,并且选出的区间数最大. 这是个典型的贪心问题了.按区间的结束位置排序,然后顺序地选取区间,只要当前 ...

  8. C++ static内容小结

    C++中static总结比较好的博客:http://blog.csdn.net/laixingjun/article/details/9139839 http://blog.csdn.net/xiaj ...

  9. ORA-15063: ASM discovered an insufficient number of disks for diskgroup "ASM,KEL"

    在启动ASM的时候报错,报错如下: SQL> startup ASM instance started Total System Global Area 130023424 bytes Fixe ...

  10. 结合Vim ghostscript 将源代码文件转换成语法高亮的pdf格式文档

    step 1: 安装ghostscript (debian 环境, 其他环境自行google) sudo apt-get install ghostscript step 2:  用Vim生成ps文件 ...