結果

問題 No.534 フィボナッチフィボナッチ数
ユーザー どららどらら
提出日時 2017-06-24 00:11:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,018 bytes
コンパイル時間 1,808 ms
コンパイル使用メモリ 171,256 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-07-26 17:07:04
合計ジャッジ時間 3,255 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

typedef vector<ll> vec;
typedef vector<vec> mat;
const ll MOD = 1000000007;

mat mul(mat &A, mat &B, ll mod){
  mat C(A.size(), vec(B[0].size()));
  rep(i,A.size()) rep(k,B.size()){
    rep(j,B[0].size()){
      C[i][j] = (C[i][j]+A[i][k]*B[k][j])%mod;
    }
  }
  return C;
}
mat pow(mat A, ll n, ll mod){
  mat B(A.size(), vec(A.size()));
  rep(i,A.size()) B[i][i] = 1;
  while(n>0){
    if(n&1LL) B=mul(B,A,mod);
    A=mul(A,A,mod);
    n>>=1;
  }
  return B;
}

int main(){
  ll N;
  cin >> N;

  mat a(2,vec(2,0));
  a[0][0] = 1; a[0][1] = 1;
  a[1][0] = 1; a[1][1] = 0;

  mat b = pow(a, N, MOD+1);
  ll m = b[0][1];
  if(m == 0) m = MOD-1;
  mat c = pow(a, m, MOD);
  cout << c[0][1] << endl;
  
  return 0;
}
0