题目链接: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. Web内容管理系统 Magnolia 介绍-挖掘优良的架构(1)

    Magnolia简介: Magnolia CMS是一家瑞士公司自2003年起发布的一个基于Java的开源内容管理系统.它适合且已被使用在以下领域:电子商务(例如:COOP.Migros.Rossman ...

  2. bzoj1876: [SDOI2009]SuperGCD

    更相减损数. 上手就debug了3个小时,直接给我看哭了. 3个函数都写错了是什么感受? 乘2函数要从前往后乘,这样后面的数乘2进位以后不会干扰前面的数. 除2函数要从后往前除,这样前面的数借来的位不 ...

  3. ZigZag Conversion1

    问题描述 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows ...

  4. 用Rational Rose来建立数据库表

    这里以MS SQL Server2000中已有的一个Northwind库为例,我们命名新的数据库名为NorthwindRose:我们只挑其中的两个表Customers和Employees做示例,另外我 ...

  5. Data Binding(数据绑定)用户指南

    1)介绍 这篇文章介绍了如何使用Data Binding库来写声明的layouts文件,并且用最少的代码来绑定你的app逻辑和layouts文件. Data Binding库不仅灵活而且广泛兼容- 它 ...

  6. 给table中某一列的文字右对齐

    一般来说,没写过jquery的前端人员,肯定是定义一个class,给每一行的那列加上align_r{text-align:right}.这是很麻烦的. 所以用jquery来写,可以$("ta ...

  7. MySQL 索引详解

    本文介绍了数据库索引,及其优.缺点.针对MySQL索引的特点.应用进行了详细的描述.分析了如何避免MySQL无法使用,如何使用EXPLAIN分析查询语句,如何优化MySQL索引的应用. 索引是一种特殊 ...

  8. [Papers]NSE, $\p_3u$, Lebesgue space [Kukavica-Ziane, JMP, 2007]

    $$\bex \p_3\bbu\in L^p(0,T;L^q(\bbR^3)),\quad \frac{2}{p}+\frac{3}{q}=2,\quad \frac{9}{4}\leq q\leq ...

  9. How to easily create popup menu for DevExpress treelist z

    http://www.itjungles.com/how-to-easily-create-popup-menu-for-devexpress-treelist.html Adding popup m ...

  10. slidingmenu + fragment 左右菜单滑动

                           content_frame.xml <?xml version="1.0" encoding="utf-8" ...