結果

問題 No.774 tatyamと素数大富豪
ユーザー pekempeypekempey
提出日時 2018-12-22 01:54:25
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 688 bytes
コンパイル時間 399 ms
コンパイル使用メモリ 81,768 KB
実行使用メモリ 77,516 KB
最終ジャッジ日時 2023-10-26 01:48:43
合計ジャッジ時間 16,802 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,174 ms
77,420 KB
testcase_01 AC 41 ms
54,196 KB
testcase_02 AC 1,461 ms
76,712 KB
testcase_03 AC 70 ms
73,464 KB
testcase_04 AC 43 ms
56,244 KB
testcase_05 AC 63 ms
67,288 KB
testcase_06 AC 41 ms
54,196 KB
testcase_07 RE -
testcase_08 AC 42 ms
54,200 KB
testcase_09 AC 1,002 ms
76,892 KB
testcase_10 AC 1,875 ms
77,148 KB
testcase_11 AC 1,404 ms
77,292 KB
testcase_12 AC 1,102 ms
77,480 KB
testcase_13 AC 690 ms
77,136 KB
testcase_14 AC 129 ms
76,980 KB
testcase_15 AC 1,222 ms
77,284 KB
testcase_16 AC 1,137 ms
76,832 KB
testcase_17 AC 1,633 ms
77,220 KB
testcase_18 AC 1,186 ms
77,516 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 or (n > 2 and n % 2 == 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