結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー trineutrontrineutron
提出日時 2020-11-25 19:32:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 585 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 10,812 KB
実行使用メモリ 25,004 KB
平均クエリ数 2.23
最終ジャッジ日時 2023-08-30 06:57:22
合計ジャッジ時間 3,935 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 63 ms
24,816 KB
testcase_02 AC 119 ms
24,412 KB
testcase_03 AC 122 ms
24,852 KB
testcase_04 AC 65 ms
24,448 KB
testcase_05 AC 64 ms
24,312 KB
testcase_06 AC 64 ms
24,668 KB
testcase_07 AC 62 ms
24,188 KB
testcase_08 WA -
testcase_09 AC 67 ms
24,852 KB
testcase_10 AC 70 ms
24,408 KB
testcase_11 AC 68 ms
24,484 KB
testcase_12 WA -
testcase_13 AC 70 ms
24,820 KB
testcase_14 AC 72 ms
24,944 KB
testcase_15 AC 85 ms
24,888 KB
testcase_16 AC 78 ms
24,964 KB
testcase_17 AC 81 ms
24,336 KB
testcase_18 AC 83 ms
24,524 KB
testcase_19 WA -
testcase_20 AC 108 ms
24,888 KB
testcase_21 AC 80 ms
24,436 KB
testcase_22 AC 78 ms
24,872 KB
testcase_23 AC 93 ms
24,748 KB
testcase_24 AC 86 ms
24,488 KB
testcase_25 AC 58 ms
25,004 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 - 1, n)
        if x0 and n % x0 == 0:
            print('! %d %d' % (x0, n // x0))
            exit()
        if x1 and n % x1 == 0:
            print('! %d %d' % (x1, n // x1))
            exit()
0