結果

問題 No.950 行列累乗
ユーザー LeonardoneLeonardone
提出日時 2019-12-13 03:29:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 913 bytes
コンパイル時間 666 ms
コンパイル使用メモリ 64,816 KB
実行使用メモリ 79,732 KB
最終ジャッジ日時 2023-09-08 12:22:53
合計ジャッジ時間 7,137 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;

void copy(long long *d, long long *s) {
    d[0]=s[0];d[1]=s[1];d[2]=s[2];d[3]=s[3];
}

bool equals(long long *a, long long *b) {
    return a[0]==b[0]&&a[1]==b[1]&&a[2]==b[2]&&a[3]==b[3];
}

void mul(long long *a, long long *c, long long p) {
    long long d[4];
    d[0] = (a[0] * c[0] % p + a[1] * c[2] % p) % p;
    d[1] = (a[0] * c[1] % p + a[1] * c[3] % p) % p;
    d[2] = (c[0] * a[2] % p + c[2] * a[3] % p) % p;
    d[3] = (c[1] * a[2] % p + c[3] * a[3] % p) % p;
    copy(a, d);
}

int main() {
    long long p, a[4], b[4], c[4];
    cin >> p;
    for (int i = 0; i < 4; i++) cin >> a[i];
    for (int i = 0; i < 4; i++) cin >> b[i];
    copy(c,a);
    for (int i=1; i <= p && i <= 1e8; i++) {
        if (equals(a, b)) {
            cout << i << endl;
            return 0;
        }
         mul(a, c, p);
    }
    cout << (-1) << endl;
    
    return 0;
}
0