結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー ecotteaecottea
提出日時 2022-10-19 02:09:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 657 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 87,792 KB
平均クエリ数 2.12
最終ジャッジ日時 2023-09-11 17:31:44
合計ジャッジ時間 5,728 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 164 ms
87,172 KB
testcase_03 AC 165 ms
87,316 KB
testcase_04 AC 116 ms
87,516 KB
testcase_05 AC 119 ms
86,820 KB
testcase_06 AC 119 ms
86,848 KB
testcase_07 AC 117 ms
86,848 KB
testcase_08 AC 121 ms
86,908 KB
testcase_09 AC 121 ms
87,232 KB
testcase_10 AC 125 ms
87,028 KB
testcase_11 WA -
testcase_12 AC 152 ms
87,196 KB
testcase_13 AC 122 ms
87,412 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 132 ms
87,580 KB
testcase_17 AC 133 ms
86,892 KB
testcase_18 AC 134 ms
87,240 KB
testcase_19 WA -
testcase_20 AC 156 ms
87,648 KB
testcase_21 AC 131 ms
87,224 KB
testcase_22 WA -
testcase_23 AC 147 ms
87,032 KB
testcase_24 AC 139 ms
87,116 KB
testcase_25 AC 115 ms
87,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

n = int(input())

a_list = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271]

for a in a_list:
    if (n % a == 0):
        print("!", a, n // a)
        exit(0)

    print("?", a)

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

    pow_a = pow(a, r // 2, mod=n)
    if pow_a == 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