結果

問題 No.8056 量子コンピュータで素因数分解 Easy
ユーザー Ryuhei Mori
提出日時 2020-01-29 21:34:18
言語 Scheme
(Gauche-0.9.15)
結果
AC  
実行時間 236 ms / 2,000 ms
コード長 547 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 7,072 KB
実行使用メモリ 37,472 KB
平均クエリ数 3.04
最終ジャッジ日時 2024-12-31 19:20:20
合計ジャッジ時間 5,623 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

(define (output-solution p q)
  (begin
    (display "! ")
    (display p)
    (display " ")
    (display q)
    (newline)
    (flush)))

(define n (read))

(define (itr a)
  (let1 b (gcd n a)
    (if (not (= b 1)) (output-solution b (/ n b))
    (begin
      (display "? ")
      (display a)
      (newline)
      (flush)
      (let1 r (read)
        (if (odd? r) (itr (+ a 1))
        (let1 x (expt-mod a (/ r 2) n)
        (if (= x (- n 1)) (itr (+ a 1))
        (let1 p (gcd n (+ x 1))
          (output-solution p (/ n p)))))))))))
  
(itr 2)
0