結果
| 問題 |
No.774 tatyamと素数大富豪
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-12-22 19:40:52 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 970 bytes |
| コンパイル時間 | 354 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 26,304 KB |
| 最終ジャッジ日時 | 2024-09-25 10:15:11 |
| 合計ジャッジ時間 | 6,614 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 5 |
| other | TLE * 1 -- * 13 |
コンパイルメッセージ
Syntax OK
ソースコード
class Integer
def prime?
n = self.abs()
return true if n == 2
return false if n == 1 || n & 1 == 0
d = n-1
d >>= 1 while d & 1 == 0
5.times do # 20 は上の説明の k に相当
a = rand(n-2) + 1
t = d
y = ModMath.pow(a,t,n) # 実装コードは下にある
while t != n-1 && y != 1 && y != n-1
y = (y * y) % n
t <<= 1
end
return false if y != n-1 && t & 1 == 0
end
return true
end
end
module ModMath
def ModMath.pow(base, power, mod)
result = 1
while power > 0
result = (result * base) % mod if power & 1 == 1
base = (base * base) % mod
power >>= 1;
end
result
end
end
n = gets.to_i
arr = gets.chomp.split
ans = -1
arr.permutation(n) do |a|
x = a.join.to_i
if x.prime?
ans = (x > ans ? x : ans)
end
end
p ans