Everybody knows Fibonacci numbers, now we are talking about the Tribonacci numbers: 
T[0] = T[1] = T[2] = 1; 
T[n] = T[n - 1] + T[n - 2] + T[n - 3] (n >= 3)

Given a and b, you are asked to calculate the sum from the ath Fibonacci number to the bth Fibonacci number, mod 1,000,000,007, that is (T[a] + T[a + 1] + ... + T[b]) % 1,000,000,007.

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

;
;

__int64 N;

void multipy( __int64 a[MAX_N][MAX_N], __int64 b[MAX_N][MAX_N], __int64 c[MAX_N][MAX_N] ){
    ; i <= ; i++ ){
        ; j <= ; j++ ){
            c[i][j] = ;
            ; k <= ; k++ ){
                c[i][j] = ( c[i][j] + a[i][k] * b[k][j] % MOD ) % MOD;
            }
        }
    }
}

void get_matrix_pow( __int64 a[MAX_N][MAX_N], __int64 n ){
    __int64 ans[MAX_N][MAX_N] = {};
    __int64 temp[MAX_N][MAX_N];
    ; i <= ; i++ )   ans[i][i] = ;

    while( n ){
         ==  ){
            multipy( ans, a, temp );
            memcpy( ans, temp, sizeof( __int64 ) * MAX_N * MAX_N );
        }
        multipy( a, a, temp );
        memcpy( a, temp, sizeof( __int64 ) * MAX_N * MAX_N );
        n /= ;
    }
    memcpy( a, ans, sizeof( __int64 ) * MAX_N * MAX_N );
}

__int64 solve( __int64 n ){
    __int64 a[MAX_N][MAX_N] = {};
     ){
        ;
    }
     ){
        ;
    } ){
        ;
    }
    a[][] = ;a[][] = ;a[][] = ;a[][] = ;
    a[][] = ;a[][] = ;a[][] = ;a[][] = ;
    a[][] = ;a[][] = ;a[][] = ;a[][] = ;
    a[][] = ;a[][] = ;a[][] = ;a[][] = ;
    get_matrix_pow( a, n -  );
    __int64 ans = ;
    __int64 b[MAX_N];
    b[] = b[] = b[] = ;
    b[] = ;
    ; i <= ; i++ ){
        ans = ( ans + a[][i] * b[i] % MOD ) % MOD;
    }
    return ans;
}

int main(){
    __int64 A, B;
    while( scanf( "%I64d%I64d", &A, &B ) != EOF ){
        printf(  ) + MOD ) % MOD );
    }
    ;
}

tribonacci的更多相关文章

  1. [LeetCode] 1137. N-th Tribonacci Number

    Description e Tribonacci sequence Tn is defined as follows: T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + ...

  2. 【Leetcode_easy】1137. N-th Tribonacci Number

    problem 1137. N-th Tribonacci Number solution: class Solution { public: int tribonacci(int n) { ) ; ...

  3. LeetCode.1137-第N个泰波那契数(N-th Tribonacci Number)

    这是小川的第409次更新,第441篇原创 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第260题(顺位题号是1137).Tribonacci(泰波那契)序列Tn定义如下: 对于n&g ...

  4. 1137. N-th Tribonacci Number(Memory Usage: 13.9 MB, less than 100.00% of Python3)

    其实思路很简单,套用一下普通斐波那契数列的非递归做法即可,不过这个成绩我一定要纪念一下,哈哈哈哈哈 代码在这儿: class Solution: def tribonacci(self, n: int ...

  5. 【leetcode】1137. N-th Tribonacci Number

    题目如下: The Tribonacci sequence Tn is defined as follows: T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 ...

  6. 【LeetCode】1137. N-th Tribonacci Number 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 日期 题目地址:https://leetc ...

  7. Tribonacci UVA - 12470 (简单的斐波拉契数列)(矩阵快速幂)

    题意:a1=0;a2=1;a3=2; a(n)=a(n-1)+a(n-2)+a(n-3);  求a(n) 思路:矩阵快速幂 #include<cstdio> #include<cst ...

  8. UVA12470—Tribonacci (类似斐波那契,简单题)

    题目链接:https://vjudge.net/problem/UVA-12470 题目意思:我们都知道斐波那契数列F[i]=F[i-1]+F[i-2],现在我们要算这样的一个式子T[i]=T[i-1 ...

  9. Python简单试题

    1,相乘次数 题目要求描述: 一个整数每一位上的数字相乘,判断是否为个位数,若是则程序结束 ,不是则继续相乘,要求返回相乘次数. 例:39 > 3*9=27 > 2*7=14 > 1 ...

随机推荐

  1. linux ftp 搭建和相关问题解决

    1. 查看是否安装vsftprpm –qa|grep vsftpd如果出现 vsftpd-2.0.5-16.el5_5.1 说明已经安装 vsftp 安装vsftpyum -y install vsf ...

  2. Ural 1099 Work Scheduling

    http://acm.timus.ru/problem.aspx?space=1&num=1099 题意:有n个人,很多对合作关系,每个人只能和一个人合作,求最多能选出多少人. 一般图匹配 # ...

  3. 文档整体解决方案(readthedocs、github 、sphinx)使用

    这里是总结了一下,用的工具或者平台:readthedocs.github .sphinx. 使用这三个工具即可轻松创建高效的文档管理库,可以用来翻译,水平再高一点可以写书. readthedocs 文 ...

  4. 由“Beeline连接HiveServer2后如何使用指定的队列(Yarn)运行Hive SQL语句”引发的一系列思考

    背景   我们使用的HiveServer2的版本为0.13.1-cdh5.3.2,目前的任务使用Hive SQL构建,分为两种类型:手动任务(临时分析需求).调度任务(常规分析需求),两者均通过我们的 ...

  5. LeetCode——Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  6. 乱译文档--Musca介绍

    胡乱翻译的,信,达,雅只能到达的水平.发现错误的话望留言好修改. 原文地址:http://aerosuidae.net/musca.html aerosuidae.net Musca 果蝇 A sim ...

  7. Java学习日记-2 零零碎碎

    一.使用Scanner类进行控制台的输入 文档中Scanner类的定义为A simple text scanner which can parse primitive types and string ...

  8. Navicat的快捷键

    1.ctrl+q 打开查询窗口 2.ctrl+/ 注释sql语句 3.ctrl+shift +/ 解除注释 4.ctrl+r 运行查询窗口的sql语句 5.ctrl+shift+r 只运行选中的sql ...

  9. JSP学习笔记(一):JDK的安装及环境变量的配置

    一.JDK的安装. JDK可以在Oracle(甲骨文)的官网下载,连接地址:http://www.oracle.com/technetwork/java/javase/downloads/index- ...

  10. java笔记12之面向对象初始

    1 概述 类:是一组相关的属性和行为的集合.是一个抽象的概念.     对象:是该类事物的具体表现形式.具体存在的个体. (1)面向对象思想     面向对象是基于面向过程的编程思想.         ...