Codeforces 450B Jzzhu and Sequences(矩阵快速幂)

永久关闭Windows更新的5种方法 很多家用电脑,如果系统自动更新的话,会变得越来越卡顿,且硬件型号兼容也并不完美。那么我们该如何彻底关闭Win11的自动更新呢?以下准备了5种方法,您可以根据自身实际情况选择合适的方法! 阅读详情

    f1 = x, f2 = y;
    fi = f(i-1) + f(i+1)
        fi = f(i-1)-f(i-2);


类似于斐波那契构造矩阵

| 1 -1 |

| 1 0 |


代码:

#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
struct node
{
    int s[2][2];
    node() {}
    node(int a, int b, int c, int d)
    {
        s[0][0] = a;
        s[0][1] = b;
        s[1][0] = c;
        s[1][1] = d;
    }
};

node mul(node a, node b)
{

    node t = node(0, 0, 0, 0);
    for(int i = 0; i < 2; i++)
        for(int j = 0; j < 2; j++)
            for(int k = 0; k < 2; k++)
                t.s[i][j] = (t.s[i][j]+a.s[i][k]*b.s[k][j])%mod;
    return t;
}

node mt_pow(node p, int n)
{
    node q = node(1, 0, 0, 1);
    while(n)
    {

        if(n&1) q = mul(q, p);
        p = mul(p, p);
        n /= 2;
    }
    return q;
}

int main(void)
{
    int f1, f2, n;
    while(cin >> f1 >> f2 >> n)
    {
        if(n == 1) printf("%d\n", (f1%mod+mod)%mod);
        else if(n == 2) printf("%d\n", (f2%mod+mod)%mod);
        else
        {
            node base = node(1, -1, 1, 0);
            node ans = mt_pow(base, n-2);
            int res = (ans.s[0][0]*f2+ans.s[0][1]*f1)%mod;
            if(res < 0) res += mod;
            printf("%d\n", res);
        }
    }
    return 0;
}


A - Jzzhu and Sequences
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Appoint description: 

Description

Jzzhu has invented a kind of sequences, they meet the following property:

You are given x and y, please calculate fn modulo 1000000007 (109 + 7).

Input

The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109).

Output

Output a single integer representing fn modulo 1000000007 (109 + 7).

Sample Input

Input
2 3
3
Output
1
Input
0 -1
2
Output
1000000006

Hint

In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.

In the second sample, f2 =  - 1;  - 1 modulo (109 + 7) equals (109 + 6).


【SECS】初识SECS协议 项目标题的第一位和第二位告诉下面有多少字节表示项目的长度。而项目的长度是指项目标题后面的字节数,这里第一个字节就是项目标题。1个字节可以表示的最大长度是0-255,所以只要项目标题后面的字节数小于等于254,都是0x01。 阅读详情

相关推荐

Chapter 7 Linear Voltage Regulators

这一章我们介绍LDO.

2304_76736886的博客 2783

Jzzhu and Sequences (矩阵快速幂 + 取模)

题目链接 Jzzhu has invented a kind of sequences, they meet the following property:              You are given x and y, please calculate fn modulo 1000000007 (109 + 7). Input The first l...

dianshi9974的博客 287

5G中的RedCap

5G中的redcap

大家好,我是码农老gou,一名专注于编程技术的程序员。在这个博客中,我将与大家分享我在工作和学习中的经验、见解以及一些实用的技术干货。 2532

矩阵快速幂——Jzzhu and Sequences

题目 Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, please calculate f n modulo 1000000007 (109 + 7). 输入 The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integ

不正先生的博客 266

使用 CFD 仿真进行阀门性能分析:第一部分

了解如何使用 Ansys Discovery 评估阀门性能,使工程师能够设计出更好的产品。

jkh920184196的博客 3171

setup和hold互卡问题剖析

当然,在不同corner下出现setup和hold互卡的情况也是最常见的。那么,一段timing path,如果launch clock latency为10ns,capture clock latency也为10ns,它们之间并没有common path,Data latency为1ns,Clock period为5ns。在计算setup时,launch path的ocv一般都是乘一个大于1的系数,假设是1.2,capture path的derate取0.8。这就变成了setup和hold互卡的情况了。

芯冰乐 1192

codeforces 257 div2 B

time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has invented a kind of sequences, they meet the following p

bestcode_boss的专栏 449

2、TrustZone(内含链接)——长期学习内容

ARM系列学习路径整理,希望对大家有用。

HoneyIC的博客 241

Jzzhu and Sequences题解

Jzzhu has invented a kind of sequences, they meet the following property:You are given x and y, please calculate fn modulo 1000000007 (109 + 7).InputThe first line contains two integers x and y (|x|, ...

Little_Small_Joze的博客 598

Linux ARM平台开发系列讲解(GMSL摄像头篇)1.2 MAX9296 GMSL链路配置

串行器 +解串器组成,软件需要做的就是写这三部分的驱动,让摄像头数据能到达。3. 配置解串器和串行器的GMSL链路。串行器和解串器上电成功之后,就可以配置。软件配置(注意软件只可以配置速率,2. 9296上电,使能芯片。的版本和速率,比如版本是配置。配置成功之后,就会出现串行器。的链路,其它同类型的。设备地址,我设置的是。...

DSMGUOGUO的博客 1万+

cesium单向流动线效果

在学材质的路上一去不复返了属实是,难也难在这。还请各位大佬多多指教~

就zhei? 692

数学 找规律 Jzzhu and Sequences

A - Jzzhu and Sequences Jzzhu has invented a kind of sequences, they meet the following property: You are givenxandy, please calculatefnmodulo1000...

aocan6909的博客 314

5分钟用AI搞定顶刊级引言!掌握三段式结构+避坑要点,让你的Introduction更有说服力(附提示词)

说明你是怎么来填补这个缺口的,一句话概括你的研究,再简述你采用了什么新方法、新模型或新视角,也就是创新点,最后说明你的方案是怎么克服第二段提到的缺口的,带来了哪些贡献,注意要确保方案与第二段提到的缺口一一对应。以上三段式引言模板,是非常经典的问题导向型结构,相比传统的结构,这种结构更能吸引是审稿人的注意,希望这篇分享的模板能给在你写论文引言时,提供一点帮助。上一段写好后,就在前人研究的基础上,亮出自己的方案,借助AI说明自己的研究,用了什么新方法/框架/理论/视角来填补这个缺口的。

智能AI让学术科研更容易 749

矩阵快速幂-CodeForces 450B Jzzhu and Sequences

矩阵快速幂-CodeForces 450B Jzzhu and Sequences 题目: Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, please calculate fn modulo 1000000007 (109 + 7). Input T...

njuptACMcxk的博客 390

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

【矩阵快速幂 】Codeforces 450B - Jzzhu and Sequences (公式转化)

【题目链接】click here~~ 【题目大意】 Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, please calculate fn modulo 1000000007(109 + 7). 【解题思路】

herongwei 的 BLOG 2495

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Jzzhu and Sequences CodeForces - 450B 矩阵快速幂

Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, please calculate fn modulo 1000000007 (109 + 7). Input The first line contains two int

liluoyu_1016的博客 324

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

CodeForces - 450B Jzzhu and Sequences —— 斐波那契数、矩阵快速幂

题目链接:https://vjudge.net/problem/CodeForces-450B B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

alince20008的博客 145

CodeForces 450B Jzzhu and Sequences (矩阵快速幂)

题意:给出x,y,n,求fn。 题解:矩阵快速幂 将式子变形:fffi+1 = fffi − fffi−1 我们可以得到转移矩阵: [11−10] \left[ \begin{matrix} 1 & 1 \\ -1 & 0 \\ \end{matrix} \right] [1−1​10​] 初始矩阵fff2就是{y, x}。 然后对n=1特判即可。 #define _CRT_SECURE_NO_WARNINGS #include<iostream>

gongyuandaye的博客 205

CodeForces - 450B Jzzhu and Sequences (矩阵快速幂)

Jzzhu has invented a kind of sequences, they meet the following property: You are givenxandy, please calculatefnmodulo1000000007(109 + 7). Input The first line contains two integersxand...

c3po 272

Jzzhu and Sequences CodeForces - 450B(矩阵快速幂)

CodeForces - 450B 题目 和斐波那契数列类似确定转移矩阵然后计算(以此类推) (x2x3)=(x1x2)⋅(0−111) \left( \begin{matrix} \text{x}_2& \text{x}_3\\ \end{matrix} \right) =\left( \begin{matrix} \text{x}_1& \text{x}_2\\ \e...

ssw的博客 225

Codeforces 450B. Jzzhu and Sequences 矩阵快速幂

题意:给一个函数满足以下方程: 给出f1和f2,需要求出fn的值 思路:方程可以变为fi+1 = fi - fi-1,这样就能求出递推式:(fi,fi+1)T = (0,1;-1,1)(fi-1,fi)T,之后求常量矩阵的n-2次幂再乘上(f1,f2)T即可 #include<bits/stdc++.h> using namespace std; typedef long long ...

qq_42397248的博客 181

CodeForces-450B Jzzhu and Sequences【数列+矩阵快速幂】

B. Jzzhu and Sequencestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJzzhu has invented a kind of sequences, they meet the following property:You ...

海岛Blog 1469

CodeForces - 450B. Jzzhu and Sequences(矩阵快速幂)

B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has invented a kind of sequences, they meet the follo...

LSD20164388的博客 305

CodeForces 450B Jzzhu and Sequences 矩阵快速幂

注意取mod的细节 ACcode: #include #define mod 1000000007 #define ll long long using namespace std; struct Matrix{ ll mat[2][2]; }; Matrix mul(Matrix a,Matrix b){ Matrix ret; for(int i=0;i<2;++

MY Blog 848

Jzzhu and Sequences CodeForces - 450B (矩阵快速幂)

题目链接:点我Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, please calculate fn modulo 1000000007 (1e9 + 7). InputThe first line contains two integers x and

wood 348

codeforces 450-B Jzzhu and Sequences 矩阵快速幂

B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has invented a kind of sequence

LZK1997的博客 404
上一篇: poj 3070 Fibonacci(矩阵快速幂模板题)
下一篇: fzu 1683 纪念SlingShot(矩阵快速幂)
cillyb
博客等级 码龄11年 225粉丝 497原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值