結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,187 ms
76,472 KB
testcase_01 AC 37 ms
52,436 KB
testcase_02 AC 1,277 ms
75,648 KB
testcase_03 AC 53 ms
68,472 KB
testcase_04 AC 35 ms
53,288 KB
testcase_05 AC 49 ms
63,392 KB
testcase_06 AC 36 ms
52,144 KB
testcase_07 AC 35 ms
52,936 KB
testcase_08 AC 35 ms
52,948 KB
testcase_09 AC 819 ms
76,320 KB
testcase_10 TLE -
testcase_11 AC 1,577 ms
76,532 KB
testcase_12 AC 1,086 ms
76,344 KB
testcase_13 AC 614 ms
76,276 KB
testcase_14 AC 88 ms
75,916 KB
testcase_15 AC 1,271 ms
76,104 KB
testcase_16 AC 950 ms
75,988 KB
testcase_17 AC 1,892 ms
75,780 KB
testcase_18 AC 1,223 ms
76,596 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(read().rstrip().decode().split())
ans = 0
for aa in permutations(a):
    v = ''
    for ai in aa:
        v += ai
    v = int(v)
    if miller_rabin(v):
        if ans < v:
            ans = v
print(ans if ans != 0 else -1)
0