結果
問題 | No.891 隣接3項間の漸化式 |
ユーザー |
![]() |
提出日時 | 2019-12-08 09:10:46 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,689 bytes |
コンパイル時間 | 916 ms |
コンパイル使用メモリ | 94,192 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-29 15:26:50 |
合計ジャッジ時間 | 2,316 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
ソースコード
#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.141592const 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;}