結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー 👑 MizarMizar
提出日時 2022-09-07 19:36:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 583 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 10,764 KB
実行使用メモリ 25,172 KB
平均クエリ数 2.19
最終ジャッジ日時 2023-08-30 06:57:30
合計ジャッジ時間 3,819 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
24,680 KB
testcase_01 WA -
testcase_02 AC 117 ms
24,536 KB
testcase_03 AC 116 ms
25,148 KB
testcase_04 AC 59 ms
24,572 KB
testcase_05 AC 61 ms
24,952 KB
testcase_06 AC 64 ms
24,708 KB
testcase_07 AC 62 ms
24,932 KB
testcase_08 WA -
testcase_09 AC 66 ms
24,396 KB
testcase_10 AC 65 ms
24,416 KB
testcase_11 AC 66 ms
24,468 KB
testcase_12 AC 76 ms
25,172 KB
testcase_13 AC 66 ms
24,732 KB
testcase_14 AC 70 ms
24,840 KB
testcase_15 AC 103 ms
25,088 KB
testcase_16 AC 76 ms
24,996 KB
testcase_17 AC 80 ms
24,848 KB
testcase_18 AC 83 ms
24,680 KB
testcase_19 AC 88 ms
24,588 KB
testcase_20 WA -
testcase_21 AC 78 ms
24,524 KB
testcase_22 AC 72 ms
24,676 KB
testcase_23 AC 93 ms
24,672 KB
testcase_24 AC 84 ms
24,524 KB
testcase_25 AC 59 ms
25,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

0