結果

問題 No.8056 量子コンピュータで素因数分解 Easy
ユーザー tatyam
提出日時 2020-02-04 18:19:53
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 379 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 399 ms
コンパイル使用メモリ 20,828 KB
実行使用メモリ 35,448 KB
平均クエリ数 2.19
最終ジャッジ日時 2026-06-05 08:27:43
合計ジャッジ時間 6,627 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from random import randint
from sys import exit
from math import gcd
def answer(p):
    print('!', p, n // p)
    exit(0)
n = int(input())
while True:
    x = randint(2, n - 2)
    if gcd(n, x) > 1:
        answer(gcd(n, x))
    print('?', x, flush = True)
    r = int(input())
    if r % 2 == 0:
        p = pow(x, r // 2, n) + 1
        if p != n:
            answer(gcd(n, p))
0