結果

問題 No.3056 量子コンピュータで素因数分解 Easy
ユーザー 👑 MizarMizar
提出日時 2022-09-07 20:20:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 316 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 10,788 KB
実行使用メモリ 25,124 KB
平均クエリ数 2.35
最終ジャッジ日時 2023-08-30 06:58:06
合計ジャッジ時間 4,035 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
24,652 KB
testcase_01 AC 69 ms
24,436 KB
testcase_02 AC 117 ms
24,660 KB
testcase_03 AC 124 ms
24,308 KB
testcase_04 AC 69 ms
24,580 KB
testcase_05 AC 63 ms
24,832 KB
testcase_06 AC 69 ms
24,940 KB
testcase_07 AC 62 ms
24,416 KB
testcase_08 AC 68 ms
24,792 KB
testcase_09 AC 68 ms
24,952 KB
testcase_10 AC 67 ms
24,516 KB
testcase_11 AC 68 ms
25,124 KB
testcase_12 AC 77 ms
25,124 KB
testcase_13 AC 69 ms
24,676 KB
testcase_14 AC 72 ms
24,412 KB
testcase_15 AC 85 ms
24,688 KB
testcase_16 AC 77 ms
24,516 KB
testcase_17 AC 80 ms
24,768 KB
testcase_18 AC 86 ms
24,468 KB
testcase_19 AC 90 ms
24,692 KB
testcase_20 AC 110 ms
25,000 KB
testcase_21 AC 79 ms
24,544 KB
testcase_22 AC 75 ms
24,720 KB
testcase_23 AC 90 ms
24,608 KB
testcase_24 AC 85 ms
24,800 KB
testcase_25 AC 61 ms
24,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import random
n=int(input())
g=0
while True:
	a=random.randrange(2,n-1)
	g=math.gcd(n,a)
	if g>1:
		break
	print("?",a)
	r=int(input())
	if r%2==1:
		continue
	r//=2
	m=pow(a,r,n)
	p=(m-1)%n
	g=math.gcd(n,p)
	if p>0 and g>1:
		break
	q=(m+1)%n
	g=math.gcd(n,q)
	if q>0 and g>1:
		break
print("!",g,n//g)
0