結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー LaikaLaika
提出日時 2020-02-05 03:14:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 535 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 25,624 KB
平均クエリ数 2.62
最終ジャッジ日時 2023-08-30 06:46:21
合計ジャッジ時間 4,160 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
25,532 KB
testcase_01 AC 70 ms
25,520 KB
testcase_02 AC 126 ms
24,892 KB
testcase_03 AC 129 ms
24,892 KB
testcase_04 AC 73 ms
25,336 KB
testcase_05 AC 70 ms
25,028 KB
testcase_06 AC 68 ms
24,900 KB
testcase_07 AC 69 ms
25,352 KB
testcase_08 AC 75 ms
25,380 KB
testcase_09 AC 74 ms
25,580 KB
testcase_10 AC 71 ms
25,000 KB
testcase_11 AC 72 ms
24,988 KB
testcase_12 AC 79 ms
25,432 KB
testcase_13 AC 75 ms
25,072 KB
testcase_14 AC 81 ms
25,544 KB
testcase_15 AC 92 ms
25,340 KB
testcase_16 AC 89 ms
24,908 KB
testcase_17 AC 86 ms
25,520 KB
testcase_18 AC 87 ms
25,016 KB
testcase_19 AC 128 ms
25,084 KB
testcase_20 AC 113 ms
25,624 KB
testcase_21 AC 87 ms
25,408 KB
testcase_22 AC 106 ms
25,588 KB
testcase_23 AC 98 ms
25,000 KB
testcase_24 AC 93 ms
24,820 KB
testcase_25 AC 61 ms
25,428 KB
権限があれば一括ダウンロードができます

ソースコード

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

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

    p = gcd(pow(x, r//2, n)+1, n)
    print(f'! {p} {n//p}')
    sys.exit()



0