結果

問題 No.774 tatyamと素数大富豪
ユーザー nebukuro09nebukuro09
提出日時 2018-12-22 02:26:47
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 523 ms / 2,000 ms
コード長 956 bytes
コンパイル時間 1,695 ms
コンパイル使用メモリ 77,044 KB
実行使用メモリ 96,116 KB
最終ジャッジ日時 2024-04-08 22:28:29
合計ジャッジ時間 8,700 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 463 ms
95,732 KB
testcase_01 AC 155 ms
90,996 KB
testcase_02 AC 367 ms
94,324 KB
testcase_03 AC 177 ms
94,708 KB
testcase_04 AC 154 ms
91,252 KB
testcase_05 AC 160 ms
91,380 KB
testcase_06 AC 156 ms
90,996 KB
testcase_07 AC 154 ms
90,996 KB
testcase_08 AC 155 ms
90,996 KB
testcase_09 AC 378 ms
95,348 KB
testcase_10 AC 364 ms
94,580 KB
testcase_11 AC 419 ms
95,732 KB
testcase_12 AC 523 ms
95,860 KB
testcase_13 AC 443 ms
95,476 KB
testcase_14 AC 209 ms
94,836 KB
testcase_15 AC 452 ms
96,116 KB
testcase_16 AC 405 ms
95,732 KB
testcase_17 AC 372 ms
94,964 KB
testcase_18 AC 413 ms
95,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from random import randint
from itertools import permutations

def miller_rabin(n, k = 10):
    if n == 1:
        return False
    if n == 2:
        return True
    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()))
S = set()
ans = -1

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

print ans
0