結果

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

ソースコード

diff #

(use srfi-27)

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

(define n (read))

(define (itr)
  (let* ((a (+ (random-integer (- n 3)) 2)) (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)
        (let1 x (expt-mod a (/ r 2) n)
        (if (= x (- n 1)) (itr)
        (let1 p (gcd n (+ x 1))
          (output-solution p (/ n p)))))))))))
  
(itr)
0