結果

問題 No.774 tatyamと素数大富豪
ユーザー tailstails
提出日時 2018-12-22 02:31:40
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,187 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 64,068 KB
最終ジャッジ日時 2024-04-08 22:30:04
合計ジャッジ時間 14,624 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,019 ms
56,604 KB
testcase_01 AC 87 ms
16,128 KB
testcase_02 AC 897 ms
63,940 KB
testcase_03 AC 98 ms
16,640 KB
testcase_04 AC 87 ms
16,128 KB
testcase_05 AC 89 ms
16,256 KB
testcase_06 AC 86 ms
16,128 KB
testcase_07 AC 87 ms
16,128 KB
testcase_08 AC 88 ms
16,128 KB
testcase_09 AC 1,187 ms
64,068 KB
testcase_10 AC 1,072 ms
63,940 KB
testcase_11 AC 1,051 ms
63,940 KB
testcase_12 AC 1,016 ms
53,276 KB
testcase_13 AC 1,011 ms
53,404 KB
testcase_14 AC 196 ms
20,588 KB
testcase_15 AC 1,028 ms
63,940 KB
testcase_16 AC 1,091 ms
63,944 KB
testcase_17 AC 1,001 ms
49,564 KB
testcase_18 AC 1,039 ms
63,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

  # 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
0