結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー LaikaLaika
提出日時 2020-02-05 02:59:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 704 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 10,788 KB
実行使用メモリ 25,660 KB
平均クエリ数 2.31
最終ジャッジ日時 2023-08-30 06:45:44
合計ジャッジ時間 4,063 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 68 ms
25,448 KB
testcase_02 AC 128 ms
24,916 KB
testcase_03 AC 131 ms
25,264 KB
testcase_04 AC 65 ms
25,036 KB
testcase_05 AC 68 ms
25,096 KB
testcase_06 AC 69 ms
25,276 KB
testcase_07 AC 67 ms
25,448 KB
testcase_08 AC 71 ms
25,260 KB
testcase_09 AC 71 ms
25,016 KB
testcase_10 AC 72 ms
25,316 KB
testcase_11 AC 73 ms
25,076 KB
testcase_12 AC 94 ms
25,624 KB
testcase_13 AC 73 ms
25,508 KB
testcase_14 AC 77 ms
25,340 KB
testcase_15 AC 88 ms
25,220 KB
testcase_16 AC 83 ms
25,304 KB
testcase_17 AC 86 ms
25,116 KB
testcase_18 AC 88 ms
25,588 KB
testcase_19 AC 98 ms
24,948 KB
testcase_20 AC 114 ms
24,880 KB
testcase_21 AC 87 ms
25,444 KB
testcase_22 AC 81 ms
25,088 KB
testcase_23 AC 99 ms
25,304 KB
testcase_24 AC 92 ms
25,188 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 True:
    x = random.randint(1, n-1)
    if x in done:
        continue
    done.add(x)
    if gcd(x, n) > 1:
        print(f'! {p} {q}')
        sys.exit()

    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}')
        sys.exit()
    elif p2*q2 == n:
        print(f'! {p2} {q2}')
        sys.exit()







0