結果
| 問題 |
No.434 占い
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-18 23:04:04 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 284 ms / 2,000 ms |
| コード長 | 642 bytes |
| コンパイル時間 | 232 ms |
| コンパイル使用メモリ | 81,792 KB |
| 実行使用メモリ | 77,568 KB |
| 最終ジャッジ日時 | 2024-11-22 12:56:36 |
| 合計ジャッジ時間 | 4,106 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
inv = [0, 1, 5, 0, 7, 2, 0, 4, 8, 0]
def solve(S, inv):
pow3 = 0
cum = 1
ans = int(S[0])
lenS = len(S)
if lenS == 1:
return ans
if S == '0' * lenS:
return 0
num = lenS - 1
for s in map(int, S[1:]):
n = num
d = lenS - n
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
num -= 1
return (ans - 1) % 9 + 1
T = int(input())
for t in range(T):
S = input()
print(solve(S, inv))