提出 #16869227


ソースコード 拡げる

import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((i8, i8, i8), cache=True)
def main(N, X, M):
    A = np.empty(M + 10, np.int64)
    A[0] = X
    first = np.full(M, -1, np.int64)
    n = 0
    while True:
        n += 1
        A[n] = A[n - 1] * A[n - 1] % M
        if first[A[n]] >= 0:
            period = n - first[A[n]]
            offset = first[A[n]] + 1
            break
        first[A[n]] = n
    if N <= offset:
        return A[:N].sum()
    x = A[:offset].sum()
    N -= offset
    q, r = divmod(N, period)
    x += q * A[offset:offset + period].sum()
    x += A[offset:offset + r].sum()
    return x

N, X, M = map(int, readline().split())

print(main(N, X, M))

提出情報

提出日時
問題 E - Sequence Sum
ユーザ maspy
言語 Python (3.8.2)
得点 500
コード長 856 Byte
結果 AC
実行時間 487 ms
メモリ 107408 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 24
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, max_01.txt, max_02.txt, max_03.txt, max_11.txt, max_12.txt, max_13.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
hand_01.txt AC 487 ms 105452 KiB
hand_02.txt AC 468 ms 106056 KiB
hand_03.txt AC 471 ms 106584 KiB
hand_04.txt AC 476 ms 106608 KiB
hand_05.txt AC 475 ms 106840 KiB
max_01.txt AC 477 ms 106868 KiB
max_02.txt AC 478 ms 107160 KiB
max_03.txt AC 465 ms 106768 KiB
max_11.txt AC 475 ms 107408 KiB
max_12.txt AC 467 ms 106640 KiB
max_13.txt AC 469 ms 106632 KiB
random_01.txt AC 466 ms 105568 KiB
random_02.txt AC 475 ms 105912 KiB
random_03.txt AC 479 ms 106588 KiB
random_04.txt AC 468 ms 106012 KiB
random_05.txt AC 470 ms 105996 KiB
random_06.txt AC 478 ms 106256 KiB
random_07.txt AC 481 ms 106984 KiB
random_08.txt AC 475 ms 106568 KiB
random_09.txt AC 469 ms 106284 KiB
random_10.txt AC 473 ms 106496 KiB
sample_01.txt AC 474 ms 106168 KiB
sample_02.txt AC 474 ms 106672 KiB
sample_03.txt AC 467 ms 106892 KiB