結果

問題 No.435 占い(Extra)
ユーザー rpy3cpprpy3cpp
提出日時 2016-10-18 23:45:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 809 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 17,820 KB
最終ジャッジ日時 2024-04-17 02:47:14
合計ジャッジ時間 8,832 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
17,820 KB
testcase_01 AC 25 ms
10,752 KB
testcase_02 AC 24 ms
10,752 KB
testcase_03 AC 25 ms
10,752 KB
testcase_04 AC 26 ms
10,752 KB
testcase_05 AC 26 ms
10,752 KB
testcase_06 AC 28 ms
10,880 KB
testcase_07 AC 25 ms
10,880 KB
testcase_08 AC 30 ms
10,880 KB
testcase_09 AC 30 ms
10,880 KB
testcase_10 AC 74 ms
10,752 KB
testcase_11 AC 78 ms
10,752 KB
testcase_12 AC 538 ms
10,752 KB
testcase_13 AC 546 ms
10,752 KB
testcase_14 AC 560 ms
10,752 KB
testcase_15 AC 501 ms
11,008 KB
testcase_16 AC 508 ms
11,008 KB
testcase_17 AC 713 ms
11,008 KB
testcase_18 AC 557 ms
10,752 KB
testcase_19 AC 547 ms
10,752 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

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
    if ans == 0:
        all_zero = True
    else:
        all_zero = False
    for d in range(1, lenS):
        r = ((r ^ a) + b) % m
        s = r % 10
        if s:
            all_zero = False
        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 all_zero:
        return 0
    return (ans - 1) % 9 + 1

T = int(input())
for line in sys.stdin:
    n, x, a, b, m = map(int, line.split())
    print(solve(n, x, a, b, m, inv))
0