結果

問題 No.774 tatyamと素数大富豪
ユーザー RiburaRibura
提出日時 2020-05-20 01:08:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 1,387 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 82,288 KB
実行使用メモリ 118,220 KB
最終ジャッジ日時 2024-04-09 22:48:38
合計ジャッジ時間 3,352 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 230 ms
118,220 KB
testcase_01 AC 36 ms
52,140 KB
testcase_02 AC 137 ms
75,348 KB
testcase_03 AC 42 ms
63,160 KB
testcase_04 AC 36 ms
53,016 KB
testcase_05 AC 40 ms
59,288 KB
testcase_06 AC 35 ms
53,804 KB
testcase_07 AC 38 ms
53,872 KB
testcase_08 AC 37 ms
52,860 KB
testcase_09 AC 167 ms
76,376 KB
testcase_10 AC 140 ms
75,760 KB
testcase_11 AC 140 ms
75,732 KB
testcase_12 AC 200 ms
94,092 KB
testcase_13 AC 204 ms
97,924 KB
testcase_14 AC 68 ms
75,696 KB
testcase_15 AC 141 ms
75,692 KB
testcase_16 AC 150 ms
76,064 KB
testcase_17 AC 136 ms
75,264 KB
testcase_18 AC 140 ms
75,408 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())
check = set()
for aa in permutations(a):
    v = ''
    for ai in aa:
        v += ai
    check.add(int(v))
check = list(check)
check.sort(reverse=True)
for v in check:
    if miller_rabin(v):
        print(v)
        break
else:
    print(-1)
0