• HDU 4291 A Short problem


      矩阵快速幂。最外层的取模是1e9+7,第二层的取模 L1 = (1e9+7的循环节),第三层的取模是 L2 = (L1的循环节)

    暴力找出L2, L1, 然后矩阵快速幂即可。。。

    View Code
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <vector>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <functional>
    #include <numeric>
    #include <sstream>
    #include <stack>
    
    #define CL(arr, val)    memset(arr, val, sizeof(arr))
    #define REP(i, n)       for((i) = 0; (i) < (n); ++(i))
    #define FOR(i, l, h)    for((i) = (l); (i) <= (h); ++(i))
    #define FORD(i, h, l)   for((i) = (h); (i) >= (l); --(i))
    #define L(x)    (x) << 1
    #define R(x)    (x) << 1 | 1
    #define MID(l, r)   (l + r) >> 1
    #define Min(x, y)   x < y ? x : y
    #define Max(x, y)   x < y ? y : x
    #define E(x)    (1 << (x))
    #define iabs(x) (x) < 0 ? -(x) : (x)
    #define OUT(x)  printf("%I64d\n", x)
    #define lowbit(x)   (x)&(-x)
    #define Read()    freopen("data.in", "r", stdin)
    #define Write()   freopen("data.out", "w", stdout);
    
    const double eps = 1e-8;
    typedef long long LL;
    const int inf = ~0u>>2;
    
    using namespace std;
    
    int mod;
    int l2 = 183120;
    int l1 = 222222224;
    
    struct Mat {
        LL mat[3][3];
        void init() {
            mat[0][0] = 3; mat[0][1] = 1;
            mat[1][0] = 1; mat[1][1] = 0;
        }
    }a;
    
    Mat operator * (Mat a, Mat b) {
        Mat c;
        CL(c.mat, 0);
        int i, j, k;
        REP(k, 2) {
            REP(i, 2) {
                if(a.mat[i][k] <= 0)    continue;
                REP(j, 2) {
                    if(b.mat[k][j] <= 0)    continue;
                    c.mat[i][j] = (c.mat[i][j] + (a.mat[i][k] * b.mat[k][j])%mod)%mod;
                }
            }
        }
        return c;
    }
    
    Mat operator ^ (Mat a, LL k) {
        Mat c;
        int i, j;
        REP(i, 2)    REP(j, 2)    c.mat[i][j] = (i == j);
        for(; k; k >>= 1) {
            if(k&1)    c = c*a;
            a = a*a;
        }
        return c;
    }
    
    LL solve(LL n, LL m) {
        a.init();
        mod = m;
        a = a^n;
        return a.mat[0][1];
    }
    
    int main() {
        //freopen("data.in", "r", stdin);
        LL n;
        while(cin >> n) {
            cout << solve(solve(solve(n, l2), l1), 1e9 + 7) << endl;
        }
        return 0;
    }
  • 相关阅读:
    npm version patch
    nginx 操作
    基于 Vue CLI 组件库封装,按需加载实现
    nginx 配置文件路径获取
    Laravel 生产资源路由并指定模型
    base.js,通用js方法,Js方法封装
    jquery.params.js,Jquery获取页面参数,js获取页面参数
    layui使用,LayUI select不显示,LayUI文件上传,Layui自定义校验规则
    Layer弹窗消息封装,Layer消息提示封装,Layer使用
    Html跨域js封装,前端页面跨域js,postMessage实现跨域
  • 原文地址:https://www.cnblogs.com/vongang/p/2687781.html
Copyright © 2020-2023  润新知