結果
問題 | No.774 tatyamと素数大富豪 |
ユーザー |
|
提出日時 | 2018-12-22 02:26:47 |
言語 | PyPy2 (7.3.15) |
結果 |
AC
|
実行時間 | 464 ms / 2,000 ms |
コード長 | 956 bytes |
コンパイル時間 | 374 ms |
コンパイル使用メモリ | 76,696 KB |
実行使用メモリ | 95,660 KB |
最終ジャッジ日時 | 2024-10-01 13:21:58 |
合計ジャッジ時間 | 8,424 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 14 |
ソースコード
from random import randintfrom itertools import permutationsdef miller_rabin(n, k = 10):if n == 1:return Falseif n == 2:return Trueif (n & 1) == 0:return Falseif sum(map(int, list(str(n)))) % 3 == 0:return Falsed = n - 1s = 0while (d & 1) == 0:s += 1d >>= 1for _ in xrange(k):a = randint(1, n - 1)if pow(a, d, n) == 1:continuecomposite = Truer = 1for i in xrange(s):if pow(a, r * d, n) == n - 1:composite = Falsebreakr *= 2if composite:return Falsereturn TrueN = input()A = sorted(map(int, raw_input().split()))S = set()ans = -1for p in permutations(A):n = int(''.join(map(str, p)))if n in S or n <= ans:continueif miller_rabin(n):ans = max(ans, n)S.add(n)print ans