結果

問題 No.8056 量子コンピュータで素因数分解 Easy
ユーザー fine
提出日時 2020-02-05 22:38:58
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 728 bytes
コンパイル時間 230 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 28,008 KB
平均クエリ数 2.27
最終ジャッジ日時 2024-12-31 19:53:47
合計ジャッジ時間 4,813 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import random
from math import gcd

def calc(x, n):
    cnt = 1
    hoge = x % n
    while hoge != 1:
        hoge = hoge * x % n
        cnt += 1
    return cnt
def main():
    n = int(input())
    
    while True:
        p = random.randint(1, n - 1);
        if p % 2 == 0 or gcd(n, p) != 1:
            continue
        print("? {}".format(p), flush=True)
        r = int(input())
        if r % 2 == 1:
            continue
        r >>= 1
        hoge = pow(p, r, n)
        if hoge == 1 or hoge == n - 1:
            continue
        p = gcd(hoge + 1, n)
        q = gcd(hoge + n - 1, n)
        if p * q == n:
            print("! {} {}".format(p, q), flush=True)
            break

if __name__ == "__main__":
    main()
0