結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー ecotteaecottea
提出日時 2022-10-19 02:19:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 413 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 86,716 KB
実行使用メモリ 87,692 KB
平均クエリ数 3.04
最終ジャッジ日時 2023-09-11 17:42:36
合計ジャッジ時間 11,396 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
87,120 KB
testcase_01 AC 124 ms
87,328 KB
testcase_02 AC 158 ms
86,840 KB
testcase_03 AC 160 ms
87,244 KB
testcase_04 AC 113 ms
87,680 KB
testcase_05 AC 114 ms
87,180 KB
testcase_06 AC 116 ms
86,940 KB
testcase_07 AC 112 ms
87,512 KB
testcase_08 AC 118 ms
87,692 KB
testcase_09 AC 115 ms
87,304 KB
testcase_10 AC 116 ms
87,252 KB
testcase_11 AC 134 ms
87,200 KB
testcase_12 AC 155 ms
87,336 KB
testcase_13 AC 114 ms
87,392 KB
testcase_14 AC 215 ms
86,940 KB
testcase_15 AC 219 ms
87,156 KB
testcase_16 AC 125 ms
87,364 KB
testcase_17 AC 126 ms
87,604 KB
testcase_18 AC 128 ms
87,096 KB
testcase_19 AC 210 ms
87,376 KB
testcase_20 AC 148 ms
87,396 KB
testcase_21 AC 126 ms
87,076 KB
testcase_22 AC 135 ms
87,524 KB
testcase_23 AC 140 ms
86,916 KB
testcase_24 AC 132 ms
87,364 KB
testcase_25 AC 107 ms
87,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

n = int(input())

for a in range(2, 1000):
    g = math.gcd(a, n)
    if g > 1:
        print("!", g, n // g)
        exit(0)

    print("?", a)

    r = int(input())
    if r % 2 == 1:
        continue

    pow_a = pow(a, r // 2, mod=n)
    if pow_a == n - 1:
        continue

    p = math.gcd(pow_a + 1, n)
    q = math.gcd(pow_a - 1, n)

    if p * q == n:
        print("!", p, q)
        break
0