結果

問題 No.8056 量子コンピュータで素因数分解 Easy
ユーザー ecottea
提出日時 2022-10-19 02:19:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 413 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 82,548 KB
実行使用メモリ 74,300 KB
平均クエリ数 3.04
最終ジャッジ日時 2024-06-29 07:41:19
合計ジャッジ時間 4,902 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

n = int(input())

for a in range(2, 1000):
    g = math.gcd(a, n)
    if g > 1:
        print("!", g, n // g)
        exit(0)

    print("?", a)

    r = int(input())
    if r % 2 == 1:
        continue

    pow_a = pow(a, r // 2, mod=n)
    if pow_a == n - 1:
        continue

    p = math.gcd(pow_a + 1, n)
    q = math.gcd(pow_a - 1, n)

    if p * q == n:
        print("!", p, q)
        break
0