結果

問題 No.774 tatyamと素数大富豪
ユーザー maspymaspy
提出日時 2020-03-28 14:56:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 933 bytes
コンパイル時間 1,403 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 13,408 KB
最終ジャッジ日時 2023-08-30 17:42:31
合計ジャッジ時間 5,863 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 310 ms
8,920 KB
testcase_01 AC 21 ms
8,924 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

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