結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
24,296 KB
testcase_01 AC 66 ms
24,004 KB
testcase_02 AC 107 ms
24,388 KB
testcase_03 AC 106 ms
23,872 KB
testcase_04 AC 62 ms
23,960 KB
testcase_05 AC 58 ms
23,968 KB
testcase_06 AC 61 ms
24,452 KB
testcase_07 AC 58 ms
24,432 KB
testcase_08 AC 62 ms
24,396 KB
testcase_09 AC 61 ms
24,216 KB
testcase_10 AC 63 ms
24,336 KB
testcase_11 AC 80 ms
24,404 KB
testcase_12 AC 101 ms
23,956 KB
testcase_13 AC 62 ms
24,104 KB
testcase_14 AC 158 ms
24,004 KB
testcase_15 AC 168 ms
24,524 KB
testcase_16 AC 71 ms
24,468 KB
testcase_17 AC 74 ms
24,580 KB
testcase_18 AC 75 ms
24,504 KB
testcase_19 AC 162 ms
24,208 KB
testcase_20 AC 97 ms
24,004 KB
testcase_21 AC 72 ms
24,492 KB
testcase_22 AC 84 ms
23,912 KB
testcase_23 AC 83 ms
24,136 KB
testcase_24 AC 76 ms
24,076 KB
testcase_25 AC 55 ms
24,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import sys

n = int(input())
for i in range(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