結果

問題 No.889 素数!
ユーザー hiragnhiragn
提出日時 2022-11-13 00:38:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,692 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 9,356 KB
最終ジャッジ日時 2023-10-12 13:26:59
合計ジャッジ時間 3,778 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
9,232 KB
testcase_01 AC 21 ms
9,272 KB
testcase_02 AC 20 ms
9,152 KB
testcase_03 AC 21 ms
9,164 KB
testcase_04 AC 21 ms
9,304 KB
testcase_05 AC 21 ms
9,124 KB
testcase_06 AC 21 ms
9,152 KB
testcase_07 AC 21 ms
9,200 KB
testcase_08 AC 21 ms
9,248 KB
testcase_09 AC 21 ms
9,272 KB
testcase_10 AC 21 ms
9,184 KB
testcase_11 AC 20 ms
9,204 KB
testcase_12 AC 21 ms
9,348 KB
testcase_13 AC 21 ms
9,240 KB
testcase_14 AC 20 ms
9,232 KB
testcase_15 AC 21 ms
9,160 KB
testcase_16 AC 21 ms
9,152 KB
testcase_17 AC 20 ms
9,288 KB
testcase_18 AC 20 ms
9,132 KB
testcase_19 AC 21 ms
9,244 KB
testcase_20 AC 21 ms
9,256 KB
testcase_21 AC 20 ms
9,300 KB
testcase_22 AC 21 ms
9,312 KB
testcase_23 AC 21 ms
9,324 KB
testcase_24 AC 21 ms
9,180 KB
testcase_25 AC 20 ms
9,128 KB
testcase_26 AC 20 ms
9,156 KB
testcase_27 AC 20 ms
9,240 KB
testcase_28 AC 21 ms
9,244 KB
testcase_29 AC 20 ms
9,124 KB
testcase_30 AC 21 ms
9,248 KB
testcase_31 AC 20 ms
9,152 KB
testcase_32 AC 20 ms
9,228 KB
testcase_33 AC 20 ms
9,312 KB
testcase_34 AC 20 ms
9,252 KB
testcase_35 AC 20 ms
9,236 KB
testcase_36 AC 20 ms
9,156 KB
testcase_37 AC 21 ms
9,328 KB
testcase_38 AC 21 ms
9,276 KB
testcase_39 AC 20 ms
9,300 KB
testcase_40 AC 21 ms
9,124 KB
testcase_41 AC 21 ms
9,248 KB
testcase_42 AC 21 ms
9,244 KB
testcase_43 AC 20 ms
9,244 KB
testcase_44 AC 21 ms
9,236 KB
testcase_45 AC 20 ms
9,252 KB
testcase_46 AC 21 ms
9,200 KB
testcase_47 AC 20 ms
9,356 KB
testcase_48 AC 20 ms
9,232 KB
testcase_49 AC 20 ms
9,320 KB
testcase_50 AC 20 ms
9,180 KB
testcase_51 AC 21 ms
9,168 KB
testcase_52 AC 21 ms
9,180 KB
testcase_53 AC 21 ms
9,188 KB
testcase_54 AC 21 ms
9,244 KB
testcase_55 AC 20 ms
9,236 KB
testcase_56 AC 20 ms
9,180 KB
testcase_57 AC 21 ms
9,160 KB
testcase_58 AC 21 ms
9,240 KB
testcase_59 AC 21 ms
9,232 KB
testcase_60 AC 20 ms
9,164 KB
testcase_61 AC 21 ms
9,244 KB
testcase_62 AC 20 ms
9,128 KB
testcase_63 AC 21 ms
9,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
import random
from collections import defaultdict


def is_prime(n):
    if n == 2:
        return True
    if n == 1 or n & 1 == 0:
        return False
    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    for k in range(100):
        a = random.randint(1, n - 1)
        t = d
        y = pow(a, t, n)
        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1
        if y != n - 1 and t & 1 == 0:
            return False
    return True


def prime_fact(N):
    res = defaultdict(int)
    if N == 1:
        return res
    p = 2
    while p <= 10 ** 4 and N > 1:
        if N % p == 0:
            while N % p == 0:
                res[p] += 1
                N //= p
        p += 1
    while N > 1:
        if is_prime(N):
            res[N] += 1
            break
        x = random.randrange(N)
        y = (x * x + 1) % N
        i = 1
        while True:
            d = gcd(abs(x - y), N)
            if d == 1:
                i += 1
            elif d == N:
                res[N] += 1
                return res
            else:
                res[d] += 1
                N //= d
                break
            x = (x * x + 1) % N
            y = (y * y + 1) % N
            y = (y * y + 1) % N
    return res


def main():
    n = int(input())
    if n == 0 or n == 1:
        print(n)
        exit()

    d = gcd(*list(prime_fact(n).values()))
    if is_prime(n):
        print("Sosu!")
    elif d % 2 == 0:
        print("Heihosu!")
    elif d % 3 == 0:
        print("Ripposu!")
    elif n in [6, 28]:
        print("Kanzensu!")
    else:
        print(n)


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