結果

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

ソースコード

diff #
raw source code

import random
import sys
from math import gcd
from functools import partial

input = sys.stdin.readline  
print = partial(print, flush=True)

done = set()
n = int(input())
p, q = 1, 1
while x := random.randint(1, n-1):
    if x in done:
        continue
    done.add(x)
    if gcd(x, n) > 1:
        print(f'! {gcd(x,n)} {n//gcd(x,n)}')
        sys.exit()

    print(f'? {x}')
    r = int(input())
    if r % 2 or pow(x, r//2, n) == n-1:
        continue

    p = gcd(pow(x, r//2, n)+1, n)
    print(f'! {p} {n//p}')
    sys.exit()



0