結果

問題 No.774 tatyamと素数大富豪
ユーザー maspymaspy
提出日時 2020-03-28 14:56:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,471 ms / 2,000 ms
コード長 933 bytes
コンパイル時間 1,801 ms
コンパイル使用メモリ 86,444 KB
実行使用メモリ 79,532 KB
最終ジャッジ日時 2023-08-30 17:42:41
合計ジャッジ時間 8,537 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 262 ms
79,184 KB
testcase_01 AC 88 ms
72,280 KB
testcase_02 AC 1,471 ms
78,664 KB
testcase_03 AC 108 ms
78,764 KB
testcase_04 AC 93 ms
72,584 KB
testcase_05 AC 94 ms
76,008 KB
testcase_06 AC 90 ms
72,436 KB
testcase_07 AC 92 ms
72,612 KB
testcase_08 AC 92 ms
72,472 KB
testcase_09 AC 970 ms
79,152 KB
testcase_10 AC 533 ms
79,220 KB
testcase_11 AC 315 ms
79,176 KB
testcase_12 AC 298 ms
79,532 KB
testcase_13 AC 253 ms
79,380 KB
testcase_14 AC 159 ms
79,044 KB
testcase_15 AC 334 ms
79,200 KB
testcase_16 AC 1,096 ms
78,556 KB
testcase_17 AC 374 ms
79,132 KB
testcase_18 AC 295 ms
78,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools

_, *A = map(int, read().split())
A_str = [str(x) for x in A]


def gen_nums():
    for p in itertools.permutations(A_str):
        yield int(''.join(p))


def MillerRabinTest(n, maxiter=10):
    import random
    if n == 1:
        return False
    elif n == 2:
        return True
    if not n & 1:
        return False

    d = n - 1
    while not (d & 1):
        d >>= 1

    for _ in range(maxiter):
        a = random.randint(1, n - 1)
        t = d
        x = pow(a, t, n)
        while (t != n - 1) and (x != 1) and (x != n - 1):
            x = x * x % n
            t <<= 1
        if (x != n - 1) and not (t & 1):
            return False
    return True


answer = -1
for p in gen_nums():
    if answer < p and MillerRabinTest(p):
        answer = p
print(answer)
0