結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー Ryuhei MoriRyuhei Mori
提出日時 2020-01-29 02:37:01
言語 Scheme
(Gauche-0.9.14)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 581 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 5,372 KB
実行使用メモリ 33,748 KB
平均クエリ数 2.35
最終ジャッジ日時 2023-08-30 06:43:31
合計ジャッジ時間 5,573 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
32,288 KB
testcase_01 AC 86 ms
32,160 KB
testcase_02 AC 151 ms
33,072 KB
testcase_03 AC 208 ms
33,136 KB
testcase_04 AC 88 ms
32,576 KB
testcase_05 AC 95 ms
32,768 KB
testcase_06 AC 90 ms
32,508 KB
testcase_07 AC 88 ms
32,688 KB
testcase_08 AC 109 ms
32,780 KB
testcase_09 AC 90 ms
32,076 KB
testcase_10 AC 97 ms
32,056 KB
testcase_11 AC 96 ms
32,304 KB
testcase_12 AC 97 ms
32,432 KB
testcase_13 AC 92 ms
32,424 KB
testcase_14 AC 125 ms
33,748 KB
testcase_15 AC 107 ms
32,204 KB
testcase_16 AC 105 ms
32,288 KB
testcase_17 AC 107 ms
32,728 KB
testcase_18 AC 111 ms
33,080 KB
testcase_19 AC 117 ms
32,404 KB
testcase_20 AC 136 ms
32,712 KB
testcase_21 AC 106 ms
32,404 KB
testcase_22 AC 102 ms
33,076 KB
testcase_23 AC 152 ms
32,288 KB
testcase_24 AC 115 ms
32,440 KB
testcase_25 AC 84 ms
32,296 KB
権限があれば一括ダウンロードができます

ソースコード

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