結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 163 ms
87,216 KB
testcase_03 AC 166 ms
87,068 KB
testcase_04 AC 118 ms
87,444 KB
testcase_05 AC 119 ms
86,896 KB
testcase_06 AC 120 ms
87,412 KB
testcase_07 AC 118 ms
87,392 KB
testcase_08 AC 122 ms
86,852 KB
testcase_09 AC 124 ms
86,976 KB
testcase_10 AC 122 ms
87,684 KB
testcase_11 WA -
testcase_12 AC 148 ms
87,156 KB
testcase_13 AC 120 ms
87,128 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 132 ms
87,096 KB
testcase_17 AC 137 ms
87,404 KB
testcase_18 AC 135 ms
87,136 KB
testcase_19 WA -
testcase_20 AC 156 ms
86,692 KB
testcase_21 AC 133 ms
87,244 KB
testcase_22 WA -
testcase_23 AC 141 ms
86,896 KB
testcase_24 AC 135 ms
86,736 KB
testcase_25 AC 117 ms
87,352 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