結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー 👑 MizarMizar
提出日時 2022-09-07 19:58:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 613 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 11,036 KB
実行使用メモリ 25,248 KB
平均クエリ数 2.31
最終ジャッジ日時 2023-08-30 06:57:43
合計ジャッジ時間 4,066 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
25,248 KB
testcase_01 AC 73 ms
24,724 KB
testcase_02 AC 126 ms
24,984 KB
testcase_03 AC 120 ms
24,572 KB
testcase_04 AC 63 ms
25,096 KB
testcase_05 AC 63 ms
24,500 KB
testcase_06 AC 68 ms
24,912 KB
testcase_07 AC 64 ms
24,964 KB
testcase_08 AC 67 ms
25,076 KB
testcase_09 AC 66 ms
24,732 KB
testcase_10 AC 69 ms
24,836 KB
testcase_11 AC 67 ms
24,652 KB
testcase_12 AC 119 ms
24,608 KB
testcase_13 AC 66 ms
24,500 KB
testcase_14 AC 71 ms
24,532 KB
testcase_15 AC 86 ms
25,008 KB
testcase_16 AC 77 ms
24,572 KB
testcase_17 AC 81 ms
24,372 KB
testcase_18 AC 82 ms
25,152 KB
testcase_19 AC 94 ms
25,168 KB
testcase_20 AC 107 ms
24,968 KB
testcase_21 AC 81 ms
24,516 KB
testcase_22 AC 80 ms
24,752 KB
testcase_23 AC 95 ms
24,892 KB
testcase_24 AC 86 ms
24,352 KB
testcase_25 AC 60 ms
24,756 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
    if p != 0:
        gcdp = math.gcd(n, p)
        if gcdp > 1:
            print("!", gcdp, n // gcdp)
            break
    q = (powb2 + 1) % n
    if q != 0:
        gcdq = math.gcd(n, q)
        if gcdq > 1:
            print("!", gcdq, n // gcdq)
            break
0