結果

問題 No.774 tatyamと素数大富豪
ユーザー shotoyooshotoyoo
提出日時 2021-06-16 22:05:09
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,917 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 79,392 KB
最終ジャッジ日時 2023-08-30 03:35:05
合計ジャッジ時間 27,861 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,985 ms
79,148 KB
testcase_01 AC 93 ms
72,396 KB
testcase_02 AC 1,476 ms
78,932 KB
testcase_03 AC 140 ms
78,676 KB
testcase_04 AC 97 ms
72,548 KB
testcase_05 AC 123 ms
78,344 KB
testcase_06 WA -
testcase_07 AC 96 ms
72,548 KB
testcase_08 AC 97 ms
72,288 KB
testcase_09 AC 1,530 ms
78,832 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 AC 1,786 ms
78,868 KB
testcase_13 AC 1,472 ms
78,840 KB
testcase_14 AC 216 ms
78,676 KB
testcase_15 TLE -
testcase_16 AC 1,523 ms
78,980 KB
testcase_17 TLE -
testcase_18 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))


from math import gcd
import random
def is_prime(n):
    """miller_rabinによる素数判定
    """
    l = [2,3,5,7,11,13,17,19,23,29,31,37]
    if n==1 or n in l:
        return True
    d = n-1
    s = 0
    while d%2==0:
        s += 1
        d //= 2
    for a in l:
        v = pow(a,d,n)
        if v==1 or v==n-1:
            continue
        for _ in range(s):
            v = v*v % n
            if v==n-1:
                break
        else:
            return False
    return True
def rho(n):
    """nを割り切る3以上の素数を返す(素数のときnを返す)
    """
    if is_prime(n):
        return n
    while True:
        x = y = random.randint(1,n-1)
        g = 1
        while g==1:
            x = (x*x - 3) % n
            y = (y*y - 3) % n
            y = (y*y - 3) % n
            g = gcd((x-y), n)
        if g>1:
            return rho(g)
def factor_fast(n):
    """高速な素因数分解
    """
    if n==1:
        return {}
    f = is_prime(n)
    if f:
        return {n:1}
    ans = {}
    while n%2==0:
        ans.setdefault(2, 0)
        ans[2] += 1
        n //= 2
    v = rho(n)
    while v!=n and n>1:
        ans.setdefault(v, 0)
        while n%v==0:
            n //= v
            ans[v] += 1
        if n>3 and is_prime(n):
            ans.setdefault(n,0)
            ans[n] += 1
            return ans
        v = rho(n)
    if n>1:
        ans.setdefault(n, 0)
        ans[n] += 1
    return ans

n = int(input())
a = list(map(int, input().split()))
from itertools import permutations as ps
ans = -1
for v in ps(range(n)):
    val = int("".join((str(a[i]) for i in v)))
    if is_prime(val):
        ans = max(ans, val)
print(ans)
0