結果

問題 No.774 tatyamと素数大富豪
ユーザー legosukelegosuke
提出日時 2019-10-26 13:54:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 827 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 10,748 KB
実行使用メモリ 28,692 KB
最終ジャッジ日時 2023-10-12 08:09:02
合計ジャッジ時間 6,632 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
import random

def is_prime(n: int, k: int = 25) -> bool:
    assert(n >= 0)
    if n == 2: return True
    if n < 2 or n & 1 == 0: return False

    d = n - 1
    while d & 1 == 0:
        d >>= 1

    for i in range(k):
        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 = pow(y, 2, n)
            t <<= 1
        if y != n - 1 and t & 1 == 0:
            return False
    return True

if __name__ == '__main__':
    n = int(input())
    a = map(int, input().split())
    ans = -1
    used = set()
    for p in itertools.permutations(a):
        num = int(''.join(map(str, p)))
        if num in used:
            continue
        used.add(num)
        if is_prime(num):
            ans = max(ans, num)
    print(ans)
0