結果

問題 No.435 占い(Extra)
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-04-21 09:42:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,186 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 163,816 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 02:56:32
合計ジャッジ時間 5,909 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 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 20 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
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 AC 196 ms
5,376 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

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 + v * 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