记录编号 584898 评测结果 AAAAAAAAAA
题目名称 一二三四五 最终得分 100
用户昵称 Gravatar┭┮﹏┭┮ 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2023-11-16 20:22:11 内存使用 0.00 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
//递推式子 + 矩阵快速幂 
typedef long long ll; 
const int mod = 1e5+7;
int n;
struct Matrix{
    ll a[6][6],n,m;
    void clear(){n = m = 0;memset(a,0,sizeof(a));}
    Matrix operator * (const Matrix &x)const{
        Matrix y;y.clear();
        y.n = n,y.m = m;
        for(int i = 0;i < n;i++)
            for(int j = 0;j < m;j++)
                for(int k = 0;k < m;k++)
                    y.a[i][j] = (y.a[i][j] + (a[i][k] * x.a[k][j]) % mod) % mod;
        return y;
    }
}c,f;
int main(){
    freopen("five.in","r",stdin);
    freopen("five.out","w",stdout);
    scanf("%d",&n);
    if(n == 1){
        printf("2\n");
        return 0;
    }
    n -= 1;
    f.n = 1,f.m = 6;
    f.a[0][0] = 1,f.a[0][1] = 2,f.a[0][2] = 2;
    c.n = c.m = 6;
    c.a[0][0] = 1,c.a[1][0] = 2,c.a[2][0] = 2;
    c.a[0][1] = 2,c.a[1][1] = 1,c.a[2][1] = 2;
    c.a[0][2] = 2,c.a[1][2] = 2,c.a[2][2] = 1;
    c.a[0][3] = 1,c.a[1][4] = 1,c.a[2][5] = 1;
    while(n){
        if(n & 1)f = f * c;
        c = c * c;
        n >>= 1;
    }
    printf("%lld\n",f.a[0][1]);
    
    return 0;
    
}