結果

問題 No.534 フィボナッチフィボナッチ数
ユーザー treeonetreeone
提出日時 2017-06-23 23:51:19
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,618 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 165,640 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-14 06:34:56
合計ジャッジ時間 2,830 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

// typedef double number;
typedef int number;
const number eps = 1e-8;
typedef vector<number> ARRAY;
const int mod = 1e9 + 7;
typedef vector<ARRAY> matrix;

// O( n )
matrix identity(int n) {
  matrix A(n, ARRAY(n));
  for (int i = 0; i < n; ++i) A[i][i] = 1;
  return A;
}
// O( n )
number inner_product(const ARRAY &a, const ARRAY &b) {
  number ans = 0;
  for (int i = 0; i < a.size(); ++i)
    ans += a[i] * b[i];
  return ans;
}
// O( n^2 )
ARRAY mul(const matrix &A, const ARRAY &x) {
  ARRAY y(A.size());
  for (int i = 0; i < A.size(); ++i)
    for (int j = 0; j < A[0].size(); ++j)
      y[i] = A[i][j] * x[j];
  return y;
}
// O( n^3 )
matrix mul(const matrix &A, const matrix &B) {
  matrix C(A.size(), ARRAY(B[0].size()));
  for (int i = 0; i < C.size(); ++i)
    for (int j = 0; j < C[i].size(); ++j)
      for (int k = 0; k < A[i].size(); ++k)
        C[i][j] += A[i][k] * B[k][j] % mod;
  return C;
}
// O( n^3 log e )
matrix pow(const matrix &A, int e) {
  return e == 0 ? identity(A.size())  :
     e % 2 == 0 ? pow(mul(A, A), e/2) : mul(A, pow(A, e-1));
}

signed main(){
    int n;
    cin >> n;
    vector<vector<int> > A(2, vector<int>(2, 0));
    A[0][0] = A[0][1] = A[1][0] = 1;
    A[1][1] = 0;
    vector<vector<int> > B = A;
    B = pow(A, n);
    A = pow(A, B[1][0]);
    cout << A[1][0] << endl;
}
0