結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー 👑 MizarMizar
提出日時 2022-10-02 01:24:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 482 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,688 KB
実行使用メモリ 25,100 KB
平均クエリ数 2.31
最終ジャッジ日時 2023-08-30 07:01:41
合計ジャッジ時間 3,828 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
24,444 KB
testcase_01 AC 62 ms
24,548 KB
testcase_02 AC 121 ms
24,908 KB
testcase_03 AC 120 ms
24,496 KB
testcase_04 AC 62 ms
24,408 KB
testcase_05 AC 63 ms
24,856 KB
testcase_06 AC 72 ms
24,852 KB
testcase_07 AC 63 ms
24,520 KB
testcase_08 AC 66 ms
24,472 KB
testcase_09 AC 67 ms
24,728 KB
testcase_10 AC 68 ms
24,640 KB
testcase_11 AC 66 ms
24,912 KB
testcase_12 AC 86 ms
24,528 KB
testcase_13 AC 67 ms
24,800 KB
testcase_14 AC 69 ms
25,024 KB
testcase_15 AC 81 ms
25,012 KB
testcase_16 AC 77 ms
24,464 KB
testcase_17 AC 81 ms
25,000 KB
testcase_18 AC 81 ms
25,100 KB
testcase_19 AC 90 ms
25,032 KB
testcase_20 AC 104 ms
24,672 KB
testcase_21 AC 79 ms
24,796 KB
testcase_22 AC 74 ms
24,804 KB
testcase_23 AC 92 ms
24,840 KB
testcase_24 AC 85 ms
24,440 KB
testcase_25 AC 58 ms
24,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import random
n = int(input()) # 合成数を入力
def check(v): # 出力チェック関数
    g = math.gcd(v, n)
    if g > 2 and g < n:
        print("!", g, n//g)
        exit()
while True: # 無限ループ
    a = random.randrange(2, n-1) # 2 <= a <= n-2
    check(a) # 質問前にaをチェック
    print("?", a) # 位数を質問
    r = int(input()) # 位数の回答
    if r&1 == 0: # if r is even:
        check(pow(a, r>>1, n)-1) # pow(a, r//2) % n - 1
0