結果

問題 No.435 占い(Extra)
ユーザー pekempeypekempey
提出日時 2016-11-22 19:32:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 1,554 bytes
コンパイル時間 2,227 ms
コンパイル使用メモリ 174,496 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 02:51:45
合計ジャッジ時間 4,566 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 12 ms
5,376 KB
testcase_13 AC 12 ms
5,376 KB
testcase_14 AC 13 ms
5,376 KB
testcase_15 AC 13 ms
5,376 KB
testcase_16 AC 13 ms
5,376 KB
testcase_17 AC 21 ms
5,376 KB
testcase_18 AC 13 ms
5,376 KB
testcase_19 AC 12 ms
5,376 KB
testcase_20 AC 111 ms
5,376 KB
testcase_21 AC 110 ms
5,376 KB
testcase_22 AC 113 ms
5,376 KB
testcase_23 AC 119 ms
5,376 KB
testcase_24 AC 111 ms
5,376 KB
testcase_25 AC 118 ms
5,376 KB
testcase_26 AC 113 ms
5,376 KB
testcase_27 AC 111 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 112 ms
5,376 KB
testcase_30 AC 108 ms
5,376 KB
testcase_31 AC 88 ms
5,376 KB
testcase_32 AC 93 ms
5,376 KB
testcase_33 AC 108 ms
5,376 KB
testcase_34 AC 118 ms
5,376 KB
testcase_35 AC 110 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#ifndef LOCAL
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

int in() {
    int n, c;
    while ((c = getchar()) < '0') if (c == EOF) abort();
    n = c - '0';
    while ((c = getchar()) >= '0') n = n * 10 + c - '0';
    return n;
}

void out(int n) {
    int res[11], i = 0;
    do { res[i++] = n % 10, n /= 10; } while (n);
    while (i) putchar(res[--i] + '0');
    putchar('\n');
}

int inv[] = { 0, 1, 5, 0, 7, 2, 0, 4, 8 };

pair<int, int> decomp(int n) {
    if (n == 0) return{ 0, 0 };
    int three = 0;
    while (n % 3 == 0) {
        n /= 3;
        three++;
    }
    return{ n, three };
}

int main() {
    int T = in();
    while (T--) {
        int n = in() - 1, x = in(), a = in(), b = in(), m = in();
        bool z = true;
        int nPi = 1, iPi = 1;
        int num3 = 0, den3 = 0;
        int64_t ans = 0;
        for (int i = 0; i <= n; i++, x = ((x ^ a) + b) % m) {
            int d = x % 10;
            if (d != 0) z = false;
            int cnt3 = num3 - den3;
            if (cnt3 <= 1) {
                int two = nPi * inv[iPi];
                ans += two * (cnt3 == 0 ? 1 : 3) * d;
            }
            auto num = decomp(n - i);
            auto den = decomp(i + 1);
            (nPi *= num.first) %= 9;
            (iPi *= den.first) %= 9;
            num3 += num.second;
            den3 += den.second;
        }
        ans %= 9;
        if (ans == 0) ans = 9;
        if (z) ans = 0;
        out(ans);
    }
}
0