結果

問題 No.1343 Dividing Digit
ユーザー ThetaTheta
提出日時 2022-10-13 11:34:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 875 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 10,756 KB
実行使用メモリ 19,900 KB
最終ジャッジ日時 2023-09-08 19:01:26
合計ジャッジ時間 2,281 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,420 KB
testcase_01 AC 17 ms
8,396 KB
testcase_02 AC 17 ms
8,420 KB
testcase_03 AC 58 ms
19,040 KB
testcase_04 AC 20 ms
9,208 KB
testcase_05 AC 28 ms
11,108 KB
testcase_06 AC 24 ms
10,064 KB
testcase_07 AC 32 ms
12,572 KB
testcase_08 AC 50 ms
16,688 KB
testcase_09 AC 54 ms
17,720 KB
testcase_10 AC 23 ms
9,940 KB
testcase_11 AC 31 ms
11,828 KB
testcase_12 AC 46 ms
15,840 KB
testcase_13 AC 44 ms
15,380 KB
testcase_14 AC 21 ms
9,692 KB
testcase_15 AC 30 ms
11,440 KB
testcase_16 AC 22 ms
9,932 KB
testcase_17 AC 52 ms
17,708 KB
testcase_18 AC 58 ms
18,768 KB
testcase_19 AC 44 ms
15,544 KB
testcase_20 AC 36 ms
12,904 KB
testcase_21 AC 51 ms
17,128 KB
testcase_22 AC 53 ms
17,268 KB
testcase_23 AC 59 ms
19,900 KB
testcase_24 AC 45 ms
10,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import cycle, chain
from math import inf


def calc_power_mod_loop(
        num: int, mod: int, digits: int = 1e6) -> tuple[list[int], int]:
    rests = [1]
    num_rest = num % mod
    power_num = num_rest
    ctr = 1
    while ctr < digits:
        try:
            exist_index = rests.index(power_num % mod)
            return rests, exist_index
        except ValueError:
            rests.append(power_num % mod)
            power_num *= num_rest
            ctr += 1
    return rests, -1


def main():
    N, K = map(int, input().split())
    digits = list(map(int, input().split()))
    digit_sum = sum(digits)

    K_rest = K % digit_sum

    rest = 0
    K_power = 1
    for digit in reversed(digits):
        rest += digit * K_power
        K_power = (K_power * K_rest) % digit_sum
    print(rest % digit_sum)


if __name__ == "__main__":
    main()
0