結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー tskrextskrex
提出日時 2020-02-05 03:29:02
言語 Ruby
(3.3.0)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 405 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 11,344 KB
実行使用メモリ 31,816 KB
平均クエリ数 2.35
最終ジャッジ日時 2023-08-30 06:47:26
合計ジャッジ時間 5,847 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
31,052 KB
testcase_01 AC 129 ms
31,240 KB
testcase_02 AC 178 ms
31,676 KB
testcase_03 AC 178 ms
31,464 KB
testcase_04 AC 136 ms
31,788 KB
testcase_05 AC 131 ms
31,684 KB
testcase_06 AC 137 ms
31,508 KB
testcase_07 AC 127 ms
31,112 KB
testcase_08 AC 137 ms
31,744 KB
testcase_09 AC 129 ms
31,168 KB
testcase_10 AC 129 ms
31,816 KB
testcase_11 AC 129 ms
31,400 KB
testcase_12 AC 136 ms
31,364 KB
testcase_13 AC 133 ms
31,248 KB
testcase_14 AC 135 ms
31,560 KB
testcase_15 AC 158 ms
31,520 KB
testcase_16 AC 138 ms
31,704 KB
testcase_17 AC 144 ms
31,140 KB
testcase_18 AC 150 ms
31,292 KB
testcase_19 AC 153 ms
31,744 KB
testcase_20 AC 169 ms
31,076 KB
testcase_21 AC 146 ms
31,140 KB
testcase_22 AC 154 ms
31,248 KB
testcase_23 AC 158 ms
31,060 KB
testcase_24 AC 149 ms
31,196 KB
testcase_25 AC 125 ms
30,868 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def query(a)
  puts "? #{a}"
  STDOUT.flush
  gets.to_i
end

n = gets.to_i
g = -1

loop do
  a = rand(2...n)
  g = n.gcd(a)
  if g != 1
    break
  else
    t = query(a)
    if t % 2 == 1
      next
    end
    b = a.pow(t/2, n)
    g = n.gcd(b-1)
    if g != 1
      break
    end
    if b == n-1
      next
    end
    g = n.gcd(b+1)
    if g != 1
      break
    end
  end
end

puts "! #{g} #{n / g}"
0