結果

問題 No.774 tatyamと素数大富豪
ユーザー nebukuro09nebukuro09
提出日時 2018-12-22 02:04:20
言語 PyPy2
(7.3.15)
結果
TLE  
実行時間 -
コード長 818 bytes
コンパイル時間 439 ms
コンパイル使用メモリ 77,564 KB
実行使用メモリ 103,916 KB
最終ジャッジ日時 2023-10-26 01:50:18
合計ジャッジ時間 6,963 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 #

from random import randint
from itertools import permutations

def miller_rabin(n, k = 10):
    if (n & 1) == 0:
        return False
    if sum(map(int, list(str(n)))) % 3 == 0:
        return False
    d = n - 1
    s = 0
    while (d & 1) == 0:
        s += 1
        d >>= 1
    for _ in xrange(k):
        a = randint(1, n - 1)
        if pow(a, d, n) == 1:
            continue
        composite = True
        r = 1
        for i in xrange(s):
            if pow(a, r * d, n) == n - 1:
                composite = False
                break
            r *= 2
        if composite:
            return False
    return True


N = input()
A = sorted(map(int, raw_input().split()))
ans = -1

for p in permutations(A):
    n = int(''.join(map(str, p)))
    if miller_rabin(n):
        ans = max(ans, n)

print ans
0