結果

問題 No.2125 Inverse Sum
ユーザー gr1msl3ygr1msl3y
提出日時 2022-11-26 11:05:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 494 bytes
コンパイル時間 214 ms
コンパイル使用メモリ 82,372 KB
実行使用メモリ 91,384 KB
最終ジャッジ日時 2024-04-10 12:44:14
合計ジャッジ時間 3,281 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,940 KB
testcase_01 AC 36 ms
52,732 KB
testcase_02 AC 36 ms
53,732 KB
testcase_03 AC 36 ms
52,976 KB
testcase_04 AC 36 ms
53,916 KB
testcase_05 AC 45 ms
60,328 KB
testcase_06 AC 41 ms
59,500 KB
testcase_07 AC 40 ms
58,776 KB
testcase_08 AC 40 ms
59,008 KB
testcase_09 AC 37 ms
52,660 KB
testcase_10 AC 44 ms
59,360 KB
testcase_11 AC 36 ms
53,168 KB
testcase_12 AC 36 ms
52,628 KB
testcase_13 AC 40 ms
57,956 KB
testcase_14 AC 43 ms
61,020 KB
testcase_15 AC 40 ms
58,688 KB
testcase_16 AC 45 ms
60,732 KB
testcase_17 AC 42 ms
59,016 KB
testcase_18 AC 41 ms
59,644 KB
testcase_19 AC 40 ms
59,208 KB
testcase_20 AC 48 ms
61,764 KB
testcase_21 AC 40 ms
58,848 KB
testcase_22 AC 39 ms
58,820 KB
testcase_23 AC 40 ms
58,352 KB
testcase_24 AC 40 ms
58,176 KB
testcase_25 AC 38 ms
59,012 KB
testcase_26 AC 36 ms
53,404 KB
testcase_27 AC 179 ms
91,384 KB
testcase_28 AC 164 ms
87,708 KB
testcase_29 AC 90 ms
80,948 KB
testcase_30 AC 36 ms
52,872 KB
testcase_31 AC 164 ms
87,772 KB
testcase_32 AC 122 ms
70,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
P, Q = map(int, input().split())
g = gcd(P, Q)
P //= g
Q //= g
div_Q = set()
for i in range(1, int(Q**0.5)+1):
    if Q % i == 0:
        div_Q.add(i)
        div_Q.add(Q//i)

S = set()
for s in div_Q:
    for t in div_Q:
        S.add(s*t)

S = sorted(list(S))
ans = []
for s in S:
    n = (s+Q)//P
    if P*n-Q != s:
        continue
    t = Q**2//s
    m = (t+Q)//P
    if P*m-Q != t:
        continue
    ans.append([n, m])

print(len(ans))
for a in ans:
    print(*a)
0