結果
| 問題 | No.774 tatyamと素数大富豪 | 
| コンテスト | |
| ユーザー |  maspy | 
| 提出日時 | 2020-03-28 14:55:50 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,520 ms / 2,000 ms | 
| コード長 | 933 bytes | 
| コンパイル時間 | 459 ms | 
| コンパイル使用メモリ | 82,660 KB | 
| 実行使用メモリ | 77,912 KB | 
| 最終ジャッジ日時 | 2025-01-02 11:18:58 | 
| 合計ジャッジ時間 | 8,150 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 14 | 
ソースコード
#!/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=20):
    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)
            
            
            
        