結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー LaikaLaika
提出日時 2020-02-05 02:50:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 625 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 25,096 KB
平均クエリ数 0.04
最終ジャッジ日時 2023-08-30 06:44:33
合計ジャッジ時間 3,629 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import random
import sys
from math import gcd

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

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

    p1, p2 = gcd(pow(x, r//2, n)+1, n), gcd(pow(x, r//2, n)-1, n)
    q1, q2 = n//p1, n//p2
    if p1*q1 == n:
        print(f'! {p1} {q1}')
        break
    elif p2*q2 == n:
        print(f'! {p1} {q1}')
        break







0