結果

問題 No.774 tatyamと素数大富豪
ユーザー Shuz*Shuz*
提出日時 2018-06-23 15:54:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,059 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 11,008 KB
実行使用メモリ 60,912 KB
最終ジャッジ日時 2023-09-13 08:29:48
合計ジャッジ時間 6,602 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
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 #

#coding:utf8
import random
import itertools

def is_prime(q,k=50):
    q = abs(q)
    #計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    #n-1=2^s*dとし(但しaは整数、dは奇数)、dを求める
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    
    #判定をk回繰り返す
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        #[0,s-1]の範囲すべてをチェック
        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()))
v=list(itertools.permutations(a))
m=-1
s=[]
for i in v:
    p=int(float(''.join(map(str,i))))
    x=1
    for j in s:
        if j==p:
            x=0
            break
    if x:
        s.append(p)
s.sort(reverse=True)
x=1
for i in s:
    if is_prime(i):
        print(i)
        x=0
        break
if x==1:
    print(-1)
0