結果

問題 No.2125 Inverse Sum
ユーザー ntudantuda
提出日時 2022-11-22 23:10:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 921 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 81,756 KB
実行使用メモリ 83,156 KB
最終ジャッジ日時 2023-10-24 14:07:45
合計ジャッジ時間 3,271 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,608 KB
testcase_01 AC 40 ms
55,608 KB
testcase_02 AC 37 ms
55,608 KB
testcase_03 AC 38 ms
55,608 KB
testcase_04 AC 37 ms
55,608 KB
testcase_05 AC 41 ms
55,608 KB
testcase_06 AC 38 ms
55,608 KB
testcase_07 AC 40 ms
59,408 KB
testcase_08 AC 38 ms
55,608 KB
testcase_09 AC 39 ms
55,608 KB
testcase_10 AC 39 ms
55,608 KB
testcase_11 AC 39 ms
55,608 KB
testcase_12 AC 39 ms
55,608 KB
testcase_13 AC 38 ms
55,608 KB
testcase_14 AC 48 ms
64,360 KB
testcase_15 AC 42 ms
61,864 KB
testcase_16 AC 46 ms
62,168 KB
testcase_17 AC 39 ms
55,608 KB
testcase_18 AC 39 ms
55,608 KB
testcase_19 AC 38 ms
55,608 KB
testcase_20 AC 45 ms
62,168 KB
testcase_21 AC 39 ms
55,608 KB
testcase_22 AC 47 ms
61,864 KB
testcase_23 AC 42 ms
55,608 KB
testcase_24 AC 43 ms
59,408 KB
testcase_25 AC 42 ms
59,408 KB
testcase_26 AC 38 ms
55,608 KB
testcase_27 AC 202 ms
83,156 KB
testcase_28 AC 172 ms
82,488 KB
testcase_29 AC 130 ms
80,068 KB
testcase_30 AC 44 ms
55,608 KB
testcase_31 AC 183 ms
82,488 KB
testcase_32 AC 60 ms
66,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter, deque


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def n_fact(N):
    c = Counter(prime_factorize(N))
    return c


P, Q = map(int, input().split())
if P > 2 * Q:
    print(0)
    exit()

PF = n_fact(Q)
from collections import deque

q = deque([1])
for k, v in PF.items():
    q2 = deque()
    while q:
        x = q.pop()
        for i in range(2 * v + 1):
            q2.append(x * pow(k, i))
    q = q2

ans = set()
for d in q:
    if (d + Q) % P == 0:
        n = (d + Q) // P
        if Q * n % (P * n - Q) == 0:
            m = Q * n // (P * n - Q)
            ans.add((n, m))

ans = list(ans)
ans.sort()
print(len(ans))
for a in ans:
    print(*a)
0