結果

問題 No.891 隣接3項間の漸化式
ユーザー yakkiyakki
提出日時 2019-12-08 09:10:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,689 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 95,008 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-28 14:18:58
合計ジャッジ時間 2,690 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,504 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

template<typename T>
struct Mat{
    vector<vector<T>> val;
    Mat(int n, int m, T x = 0) : val(n,vector<T>(m,x)){}
    void init(int n, int m, T x = 0){
        val.assign(n,vector<T>(m,x));
    }
    size_t size(){
        return val.size();
    }
    inline vector<T>& operator [](int i){
        return val[i];
    }
};

Mat<ll> operator *(Mat<ll> A, Mat<ll> B){
    Mat<ll> R(A.size(),B[0].size());
    for(int i = 0; i < A.size(); i++){
        for(int j = 0; j < B[0].size(); j++){
            for(int k = 0; k < B.size(); k++){
                R[i][j] += A[i][k]*B[k][j]+MOD;
                R[i][j] %= MOD;
            }
        }
    }
    return R;
}

Mat<ll> pow(Mat<ll> A, ll n){
    Mat<ll> R(A.size(),A.size());
    for(int i = 0; i < A.size(); i++) R[i][i] = 1;
    while(n > 0){
        if(n&1) R = R*A;
        A = A*A;
        n >>= 1;
    }
    return R;
}
int main(){
    ll a,b,n; cin >> a >> b >> n;
    Mat<ll> mat(2,2);
    mat[0][0] = a;
    mat[0][1] = b;
    mat[1][0] = 1;
    Mat<ll> mat2 = pow(mat,n);
    cout << mat2[1][0] << endl;
}
0