結果

問題 No.774 tatyamと素数大富豪
ユーザー Shuz*Shuz*
提出日時 2018-06-23 17:53:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,057 ms / 2,000 ms
コード長 724 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 67,584 KB
最終ジャッジ日時 2024-04-08 22:25:59
合計ジャッジ時間 13,105 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 966 ms
67,584 KB
testcase_01 AC 32 ms
10,368 KB
testcase_02 AC 966 ms
67,584 KB
testcase_03 AC 43 ms
11,136 KB
testcase_04 AC 34 ms
10,368 KB
testcase_05 AC 34 ms
10,496 KB
testcase_06 AC 33 ms
10,368 KB
testcase_07 AC 32 ms
10,368 KB
testcase_08 AC 32 ms
10,368 KB
testcase_09 AC 1,035 ms
67,584 KB
testcase_10 AC 971 ms
67,584 KB
testcase_11 AC 978 ms
67,584 KB
testcase_12 AC 962 ms
67,584 KB
testcase_13 AC 969 ms
67,584 KB
testcase_14 AC 137 ms
16,896 KB
testcase_15 AC 972 ms
67,584 KB
testcase_16 AC 1,057 ms
67,584 KB
testcase_17 AC 960 ms
67,584 KB
testcase_18 AC 974 ms
67,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import random
import itertools
def is_prime(q,k=5):
    q=abs(q)
    if q==2 or q==3:return True
    if q==1:return False
    if q%2==0 or q%3==0:return False
    d=(q-1)>>1
    while d&1==0:
        d>>=1
    for i in range(k):
        a=random.randint(1,q-1)
        t=d
        y=pow(a,t,q)
        while t!=q-1 and y!=1 and y!=q-1: 
            y=pow(y,2,q)
            t<<=1
        if y!=q-1 and t&1==0:
            return False
    return True
n=int(input())
a=list(map(int,input().split()))
s=[]
for i in list(itertools.permutations(a)):
    s.append(int(''.join(map(str,i))))
s.sort(reverse=True)
p=0
for i in s:
    if p-i:
        if is_prime(i):
            print(i)
            break
    p=i
else:
    print(-1)
0