結果

問題 No.2125 Inverse Sum
ユーザー ntudantuda
提出日時 2022-11-22 22:59:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 857 bytes
コンパイル時間 1,105 ms
コンパイル使用メモリ 81,772 KB
実行使用メモリ 81,180 KB
最終ジャッジ日時 2023-10-24 14:00:15
合計ジャッジ時間 4,942 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,580 KB
testcase_01 WA -
testcase_02 AC 40 ms
55,580 KB
testcase_03 WA -
testcase_04 AC 40 ms
55,580 KB
testcase_05 AC 46 ms
55,580 KB
testcase_06 WA -
testcase_07 AC 43 ms
59,396 KB
testcase_08 AC 41 ms
55,580 KB
testcase_09 RE -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 40 ms
55,584 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 43 ms
59,400 KB
testcase_25 AC 43 ms
59,400 KB
testcase_26 AC 40 ms
55,584 KB
testcase_27 AC 201 ms
81,180 KB
testcase_28 AC 170 ms
79,852 KB
testcase_29 RE -
testcase_30 WA -
testcase_31 AC 169 ms
79,852 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

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 = []
for d in q:
    if (d - 1) % P == 0:
        n = (d + Q) // P
        m = Q * n // (P * n - Q)
        ans.append((n, m))

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