結果

問題 No.2125 Inverse Sum
ユーザー shobonvipshobonvip
提出日時 2022-11-18 21:46:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 730 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 81,708 KB
実行使用メモリ 88,132 KB
最終ジャッジ日時 2023-10-20 06:33:01
合計ジャッジ時間 3,514 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,484 KB
testcase_01 AC 38 ms
53,484 KB
testcase_02 AC 38 ms
53,484 KB
testcase_03 AC 38 ms
53,484 KB
testcase_04 AC 38 ms
53,484 KB
testcase_05 AC 47 ms
61,748 KB
testcase_06 AC 43 ms
59,700 KB
testcase_07 AC 42 ms
57,228 KB
testcase_08 AC 44 ms
57,228 KB
testcase_09 AC 44 ms
59,700 KB
testcase_10 AC 44 ms
59,700 KB
testcase_11 AC 38 ms
53,484 KB
testcase_12 AC 38 ms
53,484 KB
testcase_13 AC 41 ms
57,228 KB
testcase_14 AC 53 ms
64,184 KB
testcase_15 AC 44 ms
59,788 KB
testcase_16 AC 49 ms
61,984 KB
testcase_17 AC 42 ms
59,276 KB
testcase_18 AC 44 ms
59,768 KB
testcase_19 AC 41 ms
57,228 KB
testcase_20 AC 51 ms
62,000 KB
testcase_21 AC 43 ms
59,700 KB
testcase_22 AC 44 ms
59,768 KB
testcase_23 AC 43 ms
59,700 KB
testcase_24 AC 40 ms
57,228 KB
testcase_25 AC 41 ms
57,228 KB
testcase_26 AC 38 ms
53,484 KB
testcase_27 AC 229 ms
88,132 KB
testcase_28 AC 199 ms
83,908 KB
testcase_29 AC 153 ms
85,228 KB
testcase_30 AC 38 ms
53,484 KB
testcase_31 AC 199 ms
83,908 KB
testcase_32 AC 112 ms
72,320 KB
権限があれば一括ダウンロードができます

ソースコード

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