結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
24,324 KB
testcase_01 AC 66 ms
24,868 KB
testcase_02 AC 128 ms
24,312 KB
testcase_03 AC 120 ms
24,988 KB
testcase_04 AC 62 ms
24,704 KB
testcase_05 AC 64 ms
24,544 KB
testcase_06 AC 65 ms
24,296 KB
testcase_07 AC 65 ms
24,668 KB
testcase_08 AC 77 ms
24,584 KB
testcase_09 AC 67 ms
24,640 KB
testcase_10 AC 70 ms
24,960 KB
testcase_11 AC 67 ms
24,736 KB
testcase_12 AC 73 ms
24,568 KB
testcase_13 AC 66 ms
24,556 KB
testcase_14 AC 72 ms
24,468 KB
testcase_15 AC 105 ms
24,796 KB
testcase_16 AC 76 ms
24,756 KB
testcase_17 AC 80 ms
24,228 KB
testcase_18 AC 84 ms
24,676 KB
testcase_19 AC 92 ms
24,568 KB
testcase_20 AC 110 ms
24,176 KB
testcase_21 AC 80 ms
24,212 KB
testcase_22 AC 75 ms
24,344 KB
testcase_23 AC 91 ms
24,636 KB
testcase_24 AC 85 ms
24,676 KB
testcase_25 AC 58 ms
24,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
import random
n=int(input())
g=0
while True:
	a=random.randrange(2,n)
	g=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=gcd(n,p)
	if p>0 and g>1:
		break
	q=(m+1)%n
	g=gcd(n,q)
	if q>0 and g>1:
		break
print("!",g,n//g)
0