結果

問題 No.774 tatyamと素数大富豪
ユーザー Shuz*Shuz*
提出日時 2018-06-23 15:26:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 891 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 149,704 KB
最終ジャッジ日時 2023-09-13 08:27:31
合計ジャッジ時間 12,447 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 1,258 ms
72,688 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 141 ms
29,680 KB
testcase_07 AC 144 ms
29,728 KB
testcase_08 AC 143 ms
29,540 KB
testcase_09 AC 1,263 ms
72,716 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 WA -
testcase_16 AC 1,259 ms
72,816 KB
testcase_17 RE -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#coding:utf8
import numpy
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 xrange(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
for i in v:
    p=int(float(''.join(map(str,i))))
    if is_prime(p) and p>m:
        m=p;
print(m)
0