結果

問題 No.774 tatyamと素数大富豪
ユーザー H3PO4H3PO4
提出日時 2022-07-19 20:39:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 640 ms / 2,000 ms
コード長 779 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 144,084 KB
最終ジャッジ日時 2023-09-14 17:15:52
合計ジャッジ時間 7,163 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 640 ms
144,084 KB
testcase_01 AC 93 ms
72,428 KB
testcase_02 AC 204 ms
76,944 KB
testcase_03 AC 122 ms
78,608 KB
testcase_04 AC 96 ms
76,732 KB
testcase_05 AC 94 ms
75,920 KB
testcase_06 AC 89 ms
71,912 KB
testcase_07 AC 89 ms
72,196 KB
testcase_08 AC 90 ms
72,280 KB
testcase_09 AC 269 ms
80,332 KB
testcase_10 AC 206 ms
76,920 KB
testcase_11 AC 282 ms
78,796 KB
testcase_12 AC 602 ms
111,804 KB
testcase_13 AC 449 ms
111,568 KB
testcase_14 AC 133 ms
79,544 KB
testcase_15 AC 315 ms
79,580 KB
testcase_16 AC 232 ms
78,492 KB
testcase_17 AC 214 ms
77,696 KB
testcase_18 AC 274 ms
79,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
import random


def is_prime(n):
    """https://qiita.com/srtk86/items/609737d50c9ef5f5dc59 から拝借しています。"""
    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


N = int(input())
A = tuple(map(int, input().split()))
max_prime = -1
for t in set(itertools.permutations(A)):
    x = int("".join(map(str, t)))
    if max_prime < x and is_prime(x):
        max_prime = x
print(max_prime)
0