結果
| 問題 | 
                            No.435 占い(Extra)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-11-22 19:45:45 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,416 bytes | 
| コンパイル時間 | 2,050 ms | 
| コンパイル使用メモリ | 177,988 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-08 12:16:30 | 
| 合計ジャッジ時間 | 5,428 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 31 WA * 1 | 
ソースコード
#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;
    for (; 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, 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;
            ans += nPi * inv[iPi] * (cnt3 == 0 ? 1 : cnt3 == 1 ? 3 : 0) * d;
            if (i < n) {
                for (nPi *= n - i; nPi % 3 == 0; nPi /= 3) num3++;
                for (iPi *= i + 1; iPi % 3 == 0; iPi /= 3) den3++;
                nPi %= 9;
                iPi %= 9;
            }
        }
        out(z ? 0 : (ans - 1) % 9 + 1);
    }
}