結果

問題 No.2125 Inverse Sum
ユーザー lloyzlloyz
提出日時 2022-11-18 23:51:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 802 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 81,680 KB
実行使用メモリ 82,132 KB
最終ジャッジ日時 2023-10-20 08:45:47
合計ジャッジ時間 2,991 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,524 KB
testcase_01 AC 38 ms
53,524 KB
testcase_02 AC 38 ms
53,524 KB
testcase_03 AC 38 ms
53,524 KB
testcase_04 AC 37 ms
53,524 KB
testcase_05 AC 40 ms
53,524 KB
testcase_06 AC 38 ms
53,524 KB
testcase_07 AC 41 ms
59,616 KB
testcase_08 AC 39 ms
53,524 KB
testcase_09 AC 37 ms
53,524 KB
testcase_10 AC 37 ms
53,524 KB
testcase_11 AC 38 ms
53,524 KB
testcase_12 AC 38 ms
53,524 KB
testcase_13 AC 38 ms
53,524 KB
testcase_14 AC 44 ms
59,824 KB
testcase_15 AC 38 ms
53,524 KB
testcase_16 AC 42 ms
59,756 KB
testcase_17 AC 38 ms
53,524 KB
testcase_18 AC 37 ms
53,524 KB
testcase_19 AC 38 ms
53,524 KB
testcase_20 AC 43 ms
59,756 KB
testcase_21 AC 38 ms
53,524 KB
testcase_22 AC 38 ms
53,524 KB
testcase_23 AC 38 ms
53,524 KB
testcase_24 AC 41 ms
59,616 KB
testcase_25 AC 40 ms
59,616 KB
testcase_26 AC 38 ms
53,524 KB
testcase_27 AC 95 ms
82,132 KB
testcase_28 AC 87 ms
80,312 KB
testcase_29 AC 77 ms
76,860 KB
testcase_30 AC 38 ms
53,524 KB
testcase_31 AC 87 ms
80,312 KB
testcase_32 AC 49 ms
63,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

p, q = map(int, input().split())

pq_gcd = gcd(p, q)
p //= pq_gcd
q //= pq_gcd

PrimeCnt = []
qc = q
c = 0
while qc % 2 == 0:
    c += 1
    qc //= 2
if c > 0:
    PrimeCnt.append((2, 2 * c))
f = 3
while f * f <= qc:
    c = 0
    while qc % f == 0:
        c += 1
        qc //= f
    if c > 0:
        PrimeCnt.append((f, 2 * c))
    f += 2
if qc != 1:
    PrimeCnt.append((qc, 2))
Divisors = [1]
for pp, c in PrimeCnt:
    qq = 1
    n = len(Divisors)
    for _ in range(c):
        qq *= pp
        for i in range(n):
            Divisors.append(Divisors[i] * qq)
Divisors.sort()

ANS = []
for q_ in Divisors:
    if (q_ + q) % p == 0 and (q * q // q_ + q) % p == 0:
        ANS.append(((q_ + q) // p, (q * q // q_ + q) // p))
print(len(ANS))
for n, m in ANS:
    print(n, m)
0