結果

問題 No.774 tatyamと素数大富豪
ユーザー RiburaRibura
提出日時 2020-05-20 00:59:27
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,319 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 82,512 KB
実行使用メモリ 76,464 KB
最終ジャッジ日時 2024-04-09 22:48:14
合計ジャッジ時間 16,672 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,197 ms
75,908 KB
testcase_01 AC 36 ms
52,672 KB
testcase_02 AC 1,291 ms
75,944 KB
testcase_03 AC 55 ms
67,360 KB
testcase_04 AC 36 ms
53,012 KB
testcase_05 AC 50 ms
63,828 KB
testcase_06 AC 35 ms
52,836 KB
testcase_07 AC 35 ms
52,568 KB
testcase_08 AC 36 ms
52,572 KB
testcase_09 AC 824 ms
75,996 KB
testcase_10 TLE -
testcase_11 AC 1,579 ms
76,136 KB
testcase_12 AC 1,083 ms
76,356 KB
testcase_13 AC 613 ms
76,156 KB
testcase_14 AC 85 ms
76,140 KB
testcase_15 AC 1,270 ms
76,088 KB
testcase_16 AC 945 ms
75,712 KB
testcase_17 AC 1,896 ms
75,924 KB
testcase_18 AC 1,236 ms
76,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from itertools import permutations


def miller_rabin(n):
    # 確率的素数判定(ミラーラビン素数判定法)
    # 素数なら確実に True を返す、合成数なら確率的に False を返す
    # True が返ったなら恐らく素数で、False が返ったなら確実に合成数である
    # 参考: http://tjkendev.github.io/procon-library/python/prime/probabilistic.html
    # 検証: https://yukicoder.me/submissions/381948
    primes = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]  # 32bit: [2, 7, 61]
    if n == 2:
        return True
    if n <= 1 or n & 1 == 0:
        return False
    d = m1 = n - 1
    d //= d & -d
    for a in primes:
        if a >= n:
            return True
        t, y = d, pow(a, d, n)
        while t != m1 and y != 1 and y != m1:
            y = y * y % n
            t <<= 1
        if y != m1 and t & 1 == 0:
            return False
    return True


n = int(readline())
a = list(readline().rstrip().decode().split())
ans = 0
for aa in permutations(a):
    v = ''
    for ai in aa:
        v += ai
    v = int(v)
    if miller_rabin(v):
        ans = max(ans, v)
print(ans if ans != 0 else -1)
0