結果

問題 No.8056 量子コンピュータで素因数分解 Easy
ユーザー 👑 Mizar
提出日時 2022-09-07 19:58:15
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 613 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 28,128 KB
平均クエリ数 2.77
最終ジャッジ日時 2024-12-31 20:13:22
合計ジャッジ時間 5,487 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import random
n = int(input())
while True:
    a = random.randrange(2, n - 1)
    gcda = math.gcd(n, a)
    if gcda > 1 and gcda < n:
        print("!", gcda, n // gcda)
        break
    print("?", a)
    b = int(input())
    if b % 2 == 1:
        continue
    b2 = b // 2
    powb2 = pow(a, b2, n)
    p = (powb2 + n - 1) % n
    if p != 0:
        gcdp = math.gcd(n, p)
        if gcdp > 1:
            print("!", gcdp, n // gcdp)
            break
    q = (powb2 + 1) % n
    if q != 0:
        gcdq = math.gcd(n, q)
        if gcdq > 1:
            print("!", gcdq, n // gcdq)
            break
0