結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー tskrextskrex
提出日時 2020-02-05 03:26:47
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 413 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 11,468 KB
実行使用メモリ 31,956 KB
平均クエリ数 1.73
最終ジャッジ日時 2023-08-30 06:46:40
合計ジャッジ時間 5,348 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
31,612 KB
testcase_01 AC 123 ms
31,916 KB
testcase_02 AC 179 ms
31,288 KB
testcase_03 AC 177 ms
31,556 KB
testcase_04 AC 124 ms
31,584 KB
testcase_05 RE -
testcase_06 AC 126 ms
31,560 KB
testcase_07 AC 125 ms
31,552 KB
testcase_08 RE -
testcase_09 AC 129 ms
31,604 KB
testcase_10 AC 131 ms
31,764 KB
testcase_11 AC 130 ms
31,956 KB
testcase_12 AC 135 ms
31,244 KB
testcase_13 AC 126 ms
31,068 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 136 ms
31,416 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 148 ms
31,424 KB
testcase_20 RE -
testcase_21 AC 138 ms
31,280 KB
testcase_22 AC 135 ms
31,760 KB
testcase_23 AC 151 ms
31,580 KB
testcase_24 AC 142 ms
31,700 KB
testcase_25 AC 118 ms
30,996 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
      continue
    end
    b = a.pow(t/2, n)
    g = n.gcd(b-1)
    if g != 1
      break
    end
    if b == n-1
      continue
    end
    g = n.gcd(b+1)
    if g != 1
      break
    end
  end
end

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