結果

問題 No.774 tatyamと素数大富豪
ユーザー pekempeypekempey
提出日時 2018-12-22 01:58:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,535 ms / 2,000 ms
コード長 856 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 77,328 KB
最終ジャッジ日時 2023-10-26 01:49:28
合計ジャッジ時間 12,119 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 901 ms
77,328 KB
testcase_01 AC 40 ms
54,104 KB
testcase_02 AC 83 ms
75,904 KB
testcase_03 AC 66 ms
69,420 KB
testcase_04 AC 41 ms
56,152 KB
testcase_05 AC 58 ms
67,212 KB
testcase_06 AC 40 ms
54,104 KB
testcase_07 AC 38 ms
54,104 KB
testcase_08 AC 39 ms
54,104 KB
testcase_09 AC 85 ms
75,912 KB
testcase_10 AC 1,535 ms
77,044 KB
testcase_11 AC 1,085 ms
76,868 KB
testcase_12 AC 757 ms
77,292 KB
testcase_13 AC 416 ms
77,228 KB
testcase_14 AC 55 ms
68,776 KB
testcase_15 AC 942 ms
77,192 KB
testcase_16 AC 968 ms
76,824 KB
testcase_17 AC 1,291 ms
77,016 KB
testcase_18 AC 916 ms
77,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import random
import itertools

def suspect(a, e, k, n):
    a = pow(a, e, n)
    if a == 1: return True
    for _ in range(k):
        if a == n - 1: return True
        a = a * a % n
    return False

def isprime(n):
    if n <= 1: return False
    if n == 2: return True
    if n == 3: return True
    if n == 5: return True
    if n % 2 == 0 or n % 3 == 0 or n % 5 == 0: return False
    e = n - 1
    k = 0
    while e % 2 == 0:
        e //= 2
        k += 1
    for _ in range(2):
        b = random.randint(2, n - 2)
        if not suspect(b, e, k, n): return False
    return True

n = int(input())
a = map(int, input().split())

ans = -1

for p in itertools.permutations(a):
    x = 0
    for e in p:
        if e >= 10:
            x = x * 100 + e
        else:
            x = x * 10 + e
    if isprime(x):
        ans = max(ans, x)
print(ans)
0