結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー 👑 MizarMizar
提出日時 2022-09-07 20:04:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 573 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 88,660 KB
平均クエリ数 2.12
最終ジャッジ日時 2023-08-30 06:57:49
合計ジャッジ時間 5,965 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
88,152 KB
testcase_01 AC 129 ms
88,424 KB
testcase_02 AC 197 ms
87,740 KB
testcase_03 AC 182 ms
88,144 KB
testcase_04 AC 131 ms
87,984 KB
testcase_05 AC 131 ms
87,964 KB
testcase_06 AC 128 ms
87,752 KB
testcase_07 AC 126 ms
88,084 KB
testcase_08 AC 132 ms
87,796 KB
testcase_09 AC 131 ms
88,112 KB
testcase_10 AC 133 ms
87,920 KB
testcase_11 AC 131 ms
87,956 KB
testcase_12 AC 154 ms
88,156 KB
testcase_13 AC 142 ms
87,980 KB
testcase_14 AC 147 ms
87,608 KB
testcase_15 AC 148 ms
88,504 KB
testcase_16 AC 144 ms
88,208 KB
testcase_17 AC 146 ms
88,092 KB
testcase_18 AC 165 ms
88,188 KB
testcase_19 AC 174 ms
88,156 KB
testcase_20 AC 185 ms
88,056 KB
testcase_21 AC 160 ms
88,252 KB
testcase_22 AC 142 ms
88,192 KB
testcase_23 AC 173 ms
88,132 KB
testcase_24 AC 153 ms
88,660 KB
testcase_25 AC 128 ms
88,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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