結果

問題 No.435 占い(Extra)
ユーザー maspy
提出日時 2020-04-24 00:35:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,094 bytes
コンパイル時間 731 ms
コンパイル使用メモリ 67,284 KB
最終ジャッジ日時 2025-01-09 22:54:18
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 5 WA * 6 RE * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
typedef long long ll;

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

void solve()
{
    ll n, x, a, b, m, comb, ord;
    cin >> n >> x >> a >> b >> m;
    n--;
    comb = 1;
    ord = 0;
    int ret = 0;
    bool all_zero = true;
    for (int i = 0; i <= n; i++)
    {
        int s = x % 10;
        all_zero &= (s == 0);
        if (ord == 0)
        {
            ret += comb * s;
        }
        else if (ord == 1)
        {
            ret += comb * 3 * s;
        }
        if (i == n)
            break;
        int t = n - i;
        while (t % 3 == 0)
        {
            t /= 3;
            ord += 1;
        }
        comb *= t;
        comb %= 9;
        t = i + 1;
        while (t % 3 == 0)
        {
            t /= 3;
            ord -= 1;
        }
        comb *= inv[t];
        comb %= 9;
        x = ((x ^ a) + b) % m;
    }
    ret %= 9;
    if (ret == 0 && !all_zero)
    {
        ret = 9;
    }
    cout << ret << endl;
}

int main()
{
    int T;
    cin >> T;
    for (int i = 0; i < T; i++)
        solve();
    return 0;
}
0