結果

問題 No.534 フィボナッチフィボナッチ数
ユーザー yukudoyukudo
提出日時 2017-06-24 00:01:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,220 bytes
コンパイル時間 2,091 ms
コンパイル使用メモリ 151,508 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-26 17:03:21
合計ジャッジ時間 2,874 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,true):false;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,true):false;}

typedef vector<ll> Array;
typedef vector<Array> Matrix;

Matrix zero(int n){ return Matrix(n, Array(n)); }

Matrix identity(int n) {
  Matrix A = zero(n);
  REP(i,n) A[i][i] = 1;
  return A;
}

Matrix mul(const Matrix &A, const Matrix& B, ll mod) {
  Matrix C( A.size(), Array(B[0].size() ) );
  REP(i, C.size()) REP(j, C[i].size()) REP(k, A[i].size()) {
      C[i][j] += A[i][k] * B[k][j];
      if (C[i][j] >= mod) C[i][j] %= mod;
  }
  return C;
}

Matrix pow(Matrix A, ll b, ll mod) {
  Matrix C = identity(A.size());
  while (b > 0) {
      if ((b & 1) == 1) C = mul(C, A, mod);
      A = mul(A, A, mod);
      b >>= 1;
  }
  return C;
}


ll f(ll n, ll mod) {
  Matrix A = zero(2);
  A[0][0] = 1;
  A[0][1] = 1;
  A[1][0] = 1;
  Matrix An = pow(A, n, mod);
  return An[0][1];
}

int main2() {
  ll N;
  cin >> N;
  cout << f(f(N, 2000000016LL), 1000000007LL) << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}
0