結果

問題 No.774 tatyamと素数大富豪
ユーザー pekempeypekempey
提出日時 2018-12-22 01:57:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,893 ms / 2,000 ms
コード長 803 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 81,768 KB
実行使用メモリ 77,476 KB
最終ジャッジ日時 2023-10-26 01:49:08
合計ジャッジ時間 14,222 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,169 ms
77,340 KB
testcase_01 AC 42 ms
54,200 KB
testcase_02 AC 149 ms
76,236 KB
testcase_03 AC 69 ms
73,548 KB
testcase_04 AC 43 ms
56,248 KB
testcase_05 AC 62 ms
67,356 KB
testcase_06 AC 42 ms
54,200 KB
testcase_07 AC 42 ms
54,200 KB
testcase_08 AC 44 ms
54,200 KB
testcase_09 AC 203 ms
76,304 KB
testcase_10 AC 1,893 ms
77,176 KB
testcase_11 AC 1,386 ms
77,224 KB
testcase_12 AC 1,001 ms
77,464 KB
testcase_13 AC 572 ms
77,304 KB
testcase_14 AC 73 ms
76,432 KB
testcase_15 AC 1,213 ms
77,288 KB
testcase_16 AC 1,141 ms
76,876 KB
testcase_17 AC 1,657 ms
77,144 KB
testcase_18 AC 1,194 ms
77,476 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(3):
        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 = ''
    for e in p:
        x += str(e)
    x = int(x)
    if isprime(x):
        ans = max(ans, x)
print(ans)
0