結果

問題 No.435 占い(Extra)
ユーザー rpy3cpp
提出日時 2016-10-19 23:06:46
言語 PyPy2
(7.3.15)
結果
MLE  
実行時間 -
コード長 743 bytes
コンパイル時間 2,377 ms
コンパイル使用メモリ 76,416 KB
実行使用メモリ 80,000 KB
最終ジャッジ日時 2024-10-08 12:09:08
合計ジャッジ時間 13,787 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample MLE * 4
other MLE * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

inv = [0, 1, 5, 0, 7, 2, 0, 4, 8, 0]

def solve(lenS, x, a, b, m, inv):
    pow3 = 0
    cum = 1
    r = x
    ans = r % 10
    if lenS == 1:
        return ans
    allzeroflag = ans
    for d in xrange(1, lenS):
        r = ((r ^ a) + b) % m
        s = r % 10
        allzeroflag += s
        n = lenS - d
        while not n % 3:
            pow3 += 1
            n //= 3
        while not d % 3:
            pow3 -= 1
            d //= 3
        cum = (cum * n * inv[d % 9]) % 9
        if pow3 < 2:
            ans += cum * s * 3 ** pow3
    if allzeroflag == 0:
        return 0
    return (ans - 1) % 9 + 1

T = int(raw_input())
for t in xrange(T):
    n, x, a, b, m = map(int, raw_input().split())
    print(solve(n, x, a, b, m, inv))
0