結果
| 問題 | No.774 tatyamと素数大富豪 | 
| コンテスト | |
| ユーザー |  tails | 
| 提出日時 | 2018-12-22 02:31:40 | 
| 言語 | Ruby (3.4.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,324 ms / 2,000 ms | 
| コード長 | 944 bytes | 
| コンパイル時間 | 245 ms | 
| コンパイル使用メモリ | 7,296 KB | 
| 実行使用メモリ | 58,180 KB | 
| 最終ジャッジ日時 | 2024-10-01 13:23:43 | 
| 合計ジャッジ時間 | 15,576 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 14 | 
コンパイルメッセージ
Syntax OK
ソースコード
  # https://ja.wikipedia.org/wiki/%E3%83%9F%E3%83%A9%E3%83%BC%E2%80%93%E3%83%A9%E3%83%93%E3%83%B3%E7%B4%A0%E6%95%B0%E5%88%A4%E5%AE%9A%E6%B3%95
  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
      10.times do
        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
A=gets.split
p A.permutation.map(&:join).map(&:to_i).sort{|a,b|b<=>a}.uniq.find(&:prime?)||-1
            
            
            
        