結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
24,056 KB
testcase_01 AC 61 ms
24,452 KB
testcase_02 AC 106 ms
24,136 KB
testcase_03 AC 106 ms
24,432 KB
testcase_04 AC 59 ms
24,372 KB
testcase_05 AC 60 ms
23,892 KB
testcase_06 AC 61 ms
23,912 KB
testcase_07 AC 59 ms
23,868 KB
testcase_08 AC 63 ms
24,112 KB
testcase_09 AC 62 ms
23,944 KB
testcase_10 AC 62 ms
24,056 KB
testcase_11 AC 65 ms
24,500 KB
testcase_12 AC 71 ms
24,164 KB
testcase_13 AC 62 ms
24,272 KB
testcase_14 AC 76 ms
23,860 KB
testcase_15 AC 79 ms
23,912 KB
testcase_16 AC 70 ms
23,808 KB
testcase_17 AC 74 ms
24,496 KB
testcase_18 AC 75 ms
24,316 KB
testcase_19 AC 89 ms
24,004 KB
testcase_20 AC 96 ms
24,244 KB
testcase_21 AC 74 ms
24,412 KB
testcase_22 AC 70 ms
24,368 KB
testcase_23 AC 83 ms
24,000 KB
testcase_24 AC 77 ms
24,124 KB
testcase_25 AC 56 ms
24,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math # 数学ライブラリ(最大公約数(greatest common divisor, gcd))のため
n = int(input()) # 合成数 n を取得
def check(v): # 出力チェック関数
    g = math.gcd(v, n)
    if g > 2 and g < n:
        print("!", g, n//g)
        exit()
check(3) # 3の素因数をチェック
for a in range(2, n-1): # a = {2,3,4,...,n-2}
    check(a) # 質問前にaをチェック
    print("?", a) # 位数を質問
    r = int(input()) # 位数の回答
    if r&1 == 0: # if r is even:
        r >>= 1
    for b in range(99): # b = {0,1,2,...,98}
        check(pow(a+b, r, n)-1) # pow(a + b, r) % n - 1
0