結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
31,164 KB
testcase_01 AC 138 ms
31,284 KB
testcase_02 AC 175 ms
31,540 KB
testcase_03 AC 181 ms
31,100 KB
testcase_04 AC 127 ms
31,260 KB
testcase_05 AC 123 ms
31,504 KB
testcase_06 AC 127 ms
31,792 KB
testcase_07 AC 125 ms
31,316 KB
testcase_08 AC 129 ms
31,504 KB
testcase_09 AC 128 ms
31,272 KB
testcase_10 AC 127 ms
31,228 KB
testcase_11 AC 126 ms
31,668 KB
testcase_12 AC 133 ms
31,628 KB
testcase_13 AC 132 ms
31,312 KB
testcase_14 AC 134 ms
31,836 KB
testcase_15 AC 168 ms
31,372 KB
testcase_16 AC 136 ms
31,436 KB
testcase_17 AC 137 ms
31,376 KB
testcase_18 AC 139 ms
31,448 KB
testcase_19 AC 147 ms
30,980 KB
testcase_20 AC 166 ms
31,532 KB
testcase_21 AC 138 ms
31,988 KB
testcase_22 AC 148 ms
31,084 KB
testcase_23 AC 149 ms
30,992 KB
testcase_24 AC 144 ms
31,380 KB
testcase_25 AC 119 ms
30,700 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# frozen_string_literal: true

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)
  break if g != 1

  t = query(a)
  next if t.odd?

  b = a.pow(t / 2, n)
  g = n.gcd(b - 1)
  break if g != 1

  next if b == n - 1

  g = n.gcd(b + 1)
  break if g != 1
end

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