結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー Lin143rdLin143rd
提出日時 2021-07-05 16:26:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 673 ms / 2,000 ms
コード長 1,774 bytes
コンパイル時間 1,015 ms
コンパイル使用メモリ 101,460 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 04:12:21
合計ジャッジ時間 4,794 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 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,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 15 ms
4,380 KB
testcase_10 AC 136 ms
4,376 KB
testcase_11 AC 671 ms
4,376 KB
testcase_12 AC 672 ms
4,376 KB
testcase_13 AC 673 ms
4,380 KB
testcase_14 AC 671 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cmath>
#include <climits>
#include <queue>
#include <bitset>
#include <set>
#include <assert.h>
#include <map>
using namespace std;
typedef vector<vector<long> > dim2veclo;
typedef vector<vector<int> > dim2vecin;
typedef vector<vector<double> > dim2vecdo;
typedef vector<vector<long long> > dim2vecll;
typedef vector<int> vecin;
typedef vector<long> veclo;
typedef vector<double> vecdo;
typedef vector<long long> vecll;
typedef vector<bool> vecbo;
typedef vector<vector<bool> > dim2vecbo;
typedef long long ll;
typedef vector < pair<ll, ll> > vecpa;
typedef vector<string> vecst;
typedef pair<ll, ll> pail;
typedef pair<int, int> pain;
typedef vector<vecpa > dim2vecpa;


#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, 1, 0, -1 };


int main() {
    ll n, m; cin >> n >> m;
    if (n == 1) {
        cout << 0 % m << endl;
        return 0;
    }
    if (n == 2) {
        cout << 1 % m << endl;
        return 0;
    }
    if (n == 3) {
        cout << 1 % m << endl;
        return 0;
    }
    dim2vecll zen = dim2vecll(2, vecll(2));
    zen[0][0] = 1;
    zen[0][1] = 1;
    zen[1][0] = 1;
    zen[1][1] = 0;
    rep(i, n - 3) {
        dim2vecll neew = dim2vecll(2, vecll(2));
        neew[0][0] = zen[0][0] + zen[1][0];
        neew[0][1] = zen[0][1] + zen[1][1];
        neew[1][0] = zen[0][0];
        neew[1][1] = zen[0][1];
        neew[0][0] = neew[0][0] % m;
        neew[0][1] = neew[0][1] % m;
        neew[1][0] = neew[1][0] % m;
        neew[1][1] = neew[1][1] % m;
        zen = neew;
    }
    cout << zen[0][0] << endl;

    return 0;
}
0