結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー trineutrontrineutron
提出日時 2020-11-25 19:34:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 607 bytes
コンパイル時間 128 ms
コンパイル使用メモリ 11,000 KB
実行使用メモリ 25,192 KB
平均クエリ数 2.35
最終ジャッジ日時 2023-08-30 06:57:34
合計ジャッジ時間 4,016 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
24,916 KB
testcase_01 AC 65 ms
24,640 KB
testcase_02 AC 119 ms
24,944 KB
testcase_03 AC 125 ms
24,604 KB
testcase_04 AC 65 ms
25,064 KB
testcase_05 AC 66 ms
24,992 KB
testcase_06 AC 69 ms
24,772 KB
testcase_07 AC 63 ms
24,580 KB
testcase_08 AC 76 ms
24,608 KB
testcase_09 AC 68 ms
24,528 KB
testcase_10 AC 68 ms
25,192 KB
testcase_11 AC 76 ms
24,920 KB
testcase_12 AC 102 ms
24,988 KB
testcase_13 AC 66 ms
24,564 KB
testcase_14 AC 74 ms
24,556 KB
testcase_15 AC 84 ms
24,488 KB
testcase_16 AC 77 ms
24,484 KB
testcase_17 AC 82 ms
24,820 KB
testcase_18 AC 91 ms
24,652 KB
testcase_19 AC 93 ms
24,748 KB
testcase_20 AC 108 ms
24,680 KB
testcase_21 AC 82 ms
24,500 KB
testcase_22 AC 78 ms
24,980 KB
testcase_23 AC 159 ms
24,388 KB
testcase_24 AC 87 ms
24,400 KB
testcase_25 AC 60 ms
24,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import sys
import random

n = int(input())
while True:
    i = random.randrange(2, n)
    if math.gcd(n, i) != 1:
        continue
    if n % i == 0:
        print('! %d %d' % (i, n // i))
        exit()
    print('? %d' % i)
    sys.stdout.flush()
    t = int(input())
    if t % 2 == 0:
        x = pow(i, t // 2, n)
        x0 = math.gcd(x + 1, n)
        x1 = math.gcd(x + n - 1, n)
        if 2 <= x0 < n and n % x0 == 0:
            print('! %d %d' % (x0, n // x0))
            exit()
        if 2 <= x1 < n and n % x1 == 0:
            print('! %d %d' % (x1, n // x1))
            exit()
0