結果

問題 No.435 占い(Extra)
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-04-21 09:43:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 222 ms / 2,000 ms
コード長 1,187 bytes
コンパイル時間 1,431 ms
コンパイル使用メモリ 163,616 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 02:56:38
合計ジャッジ時間 5,560 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 21 ms
5,376 KB
testcase_13 AC 20 ms
5,376 KB
testcase_14 AC 20 ms
5,376 KB
testcase_15 AC 21 ms
5,376 KB
testcase_16 AC 24 ms
5,376 KB
testcase_17 AC 76 ms
5,376 KB
testcase_18 AC 18 ms
5,376 KB
testcase_19 AC 20 ms
5,376 KB
testcase_20 AC 198 ms
5,376 KB
testcase_21 AC 186 ms
5,376 KB
testcase_22 AC 184 ms
5,376 KB
testcase_23 AC 177 ms
5,376 KB
testcase_24 AC 186 ms
5,376 KB
testcase_25 AC 222 ms
5,376 KB
testcase_26 AC 200 ms
5,376 KB
testcase_27 AC 171 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 189 ms
5,376 KB
testcase_30 AC 201 ms
5,376 KB
testcase_31 AC 150 ms
5,376 KB
testcase_32 AC 161 ms
5,376 KB
testcase_33 AC 172 ms
5,376 KB
testcase_34 AC 185 ms
5,376 KB
testcase_35 AC 170 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)




const int inv[9] = { 0, 1, 5, 0, 7, 2, 0, 4, 8 };
int modpow(int a, int n, int mod = 9) {
    a %= mod;
    if (a == 0) return 0;
    int r = 1;
    while (n) r = r*((n % 2) ? a : 1) % mod, a = a*a%mod, n >>= 1;
    return r;
}
int sol(int N, int X, int A, int B, int M) {
    int a = 1, b = 1, t = 0;
    int v = X;
    int isAll0 = true;
    int res = 0;
    rep(i, 0, N) {
        int vv = v % 10;
        if (vv) isAll0 = false;
        int c = a * inv[b] * modpow(3, t) % 9;
        res = (res + vv * c) % 9;
        a *= (N - 1 - i);
        b *= (i + 1);
        while (a % 3 == 0 && 0 < a) a /= 3, t++;
        while (b % 3 == 0 && 0 < b) b /= 3, t--;
        a %= 9; b %= 9;

        v = ((v ^ A) + B) % M;
    }
    if (isAll0) return 0;
    if (res == 0) res = 9;
    return res;
}
//-----------------------------------------------------------------------------------
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int T; cin >> T;
    rep(t, 0, T) {
        int N, X, A, B, M;
        cin >> N >> X >> A >> B >> M;
        printf("%d\n", sol(N, X, A, B, M));
    }
}
0