結果
| 問題 | No.8056 量子コンピュータで素因数分解 Easy |
| ユーザー |
|
| 提出日時 | 2020-02-05 02:50:46 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 625 bytes |
| 記録 | |
| コンパイル時間 | 315 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 46,092 KB |
| 最終ジャッジ日時 | 2024-12-31 19:25:54 |
| 合計ジャッジ時間 | 82,424 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 26 |
ソースコード
import random
import sys
from math import gcd
input = sys.stdin.readline
done = set()
n = int(input())
p, q = 1, 1
while True:
x = random.randint(1, n-1)
if x in done:
continue
done.add(x)
if gcd(x, n) > 1:
print(f'! {p} {q}')
exit(0)
print(f'? {x}')
r = int(input())
if r % 2:
continue
if pow(x, r//2, n) == n-1:
continue
p1, p2 = gcd(pow(x, r//2, n)+1, n), gcd(pow(x, r//2, n)-1, n)
q1, q2 = n//p1, n//p2
if p1*q1 == n:
print(f'! {p1} {q1}')
break
elif p2*q2 == n:
print(f'! {p1} {q1}')
break