結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー finefine
提出日時 2020-02-05 22:38:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 728 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 24,952 KB
平均クエリ数 2.27
最終ジャッジ日時 2023-08-30 06:51:58
合計ジャッジ時間 3,968 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
24,620 KB
testcase_01 AC 67 ms
24,816 KB
testcase_02 AC 122 ms
24,936 KB
testcase_03 AC 121 ms
24,656 KB
testcase_04 AC 65 ms
24,316 KB
testcase_05 AC 66 ms
24,508 KB
testcase_06 AC 67 ms
24,768 KB
testcase_07 AC 65 ms
24,580 KB
testcase_08 AC 71 ms
24,952 KB
testcase_09 AC 69 ms
24,388 KB
testcase_10 AC 72 ms
24,860 KB
testcase_11 AC 70 ms
24,696 KB
testcase_12 AC 105 ms
24,884 KB
testcase_13 AC 69 ms
24,544 KB
testcase_14 AC 75 ms
24,248 KB
testcase_15 AC 84 ms
24,532 KB
testcase_16 AC 79 ms
24,540 KB
testcase_17 AC 84 ms
24,308 KB
testcase_18 AC 85 ms
24,460 KB
testcase_19 AC 91 ms
24,368 KB
testcase_20 AC 110 ms
24,232 KB
testcase_21 AC 82 ms
24,444 KB
testcase_22 AC 85 ms
24,140 KB
testcase_23 AC 95 ms
24,528 KB
testcase_24 AC 87 ms
24,540 KB
testcase_25 AC 61 ms
24,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import random
from math import gcd

def calc(x, n):
    cnt = 1
    hoge = x % n
    while hoge != 1:
        hoge = hoge * x % n
        cnt += 1
    return cnt
def main():
    n = int(input())
    
    while True:
        p = random.randint(1, n - 1);
        if p % 2 == 0 or gcd(n, p) != 1:
            continue
        print("? {}".format(p), flush=True)
        r = int(input())
        if r % 2 == 1:
            continue
        r >>= 1
        hoge = pow(p, r, n)
        if hoge == 1 or hoge == n - 1:
            continue
        p = gcd(hoge + 1, n)
        q = gcd(hoge + n - 1, n)
        if p * q == n:
            print("! {} {}".format(p, q), flush=True)
            break

if __name__ == "__main__":
    main()
0