結果

問題 No.2125 Inverse Sum
ユーザー shobonvip
提出日時 2022-11-18 21:46:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 730 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 82,492 KB
実行使用メモリ 88,448 KB
最終ジャッジ日時 2024-09-20 02:09:12
合計ジャッジ時間 3,275 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

def makediv(n):
	lower_divisors , upper_divisors = [], []
	i = 1
	while i*i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n//i)
		i += 1
	return lower_divisors + upper_divisors[::-1]

p,q = map(int,input().split())
# (pn-q)(pm-q) = q^2
# AND pn-q > 0, pm-q > 0

x = makediv(q)
s = set()
g = []

for i in x:
	for j in x:
		if i*j not in s:
			g.append(i*j)
			s.add(i*j)

ans = []
for l in g:
	r = q * q // l
	if q + l > 0 and q + r > 0 and (q + l) % p == 0 and (q + r) % p == 0:
		ans.append(((q+l)//p, (q+r)//p))
	if q - l > 0 and q - r > 0 and (q - l) % p == 0 and (q - r) % p == 0:
		ans.append(((q-l)//p, (q-r)//p))

ans.sort()
print(len(ans))
for i in ans:
	print(i[0], i[1])
0