結果

問題 No.8056 量子コンピュータで素因数分解 Easy
ユーザー Mizar
提出日時 2022-09-07 20:32:19
言語 Python3
(3.15.2 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 104 ms / 2,000 ms
+ 1µs
コード長 308 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 57 ms
コンパイル使用メモリ 15,104 KB
実行使用メモリ 11,392 KB
平均クエリ数 2.35
最終ジャッジ日時 2026-10-10 00:55:20
合計ジャッジ時間 3,185 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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