結果

問題 No.2125 Inverse Sum
ユーザー shobonvip
提出日時 2022-11-18 21:44:34
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 634 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 82,172 KB
実行使用メモリ 64,448 KB
最終ジャッジ日時 2024-09-20 02:07:10
合計ジャッジ時間 3,911 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 2 TLE * 1 -- * 27
権限があれば一括ダウンロードができます

ソースコード

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

ans = []
for l in makediv(q * q):
	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