結果

問題 No.2125 Inverse Sum
ユーザー lloyzlloyz
提出日時 2022-11-18 23:46:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 836 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 81,628 KB
実行使用メモリ 82,184 KB
最終ジャッジ日時 2023-10-20 08:42:20
合計ジャッジ時間 3,092 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,580 KB
testcase_01 AC 37 ms
53,580 KB
testcase_02 AC 36 ms
53,516 KB
testcase_03 AC 36 ms
53,580 KB
testcase_04 WA -
testcase_05 AC 40 ms
53,580 KB
testcase_06 AC 36 ms
53,580 KB
testcase_07 AC 41 ms
59,680 KB
testcase_08 WA -
testcase_09 AC 36 ms
53,580 KB
testcase_10 AC 37 ms
53,580 KB
testcase_11 AC 36 ms
53,580 KB
testcase_12 WA -
testcase_13 AC 37 ms
53,580 KB
testcase_14 AC 42 ms
59,884 KB
testcase_15 AC 38 ms
53,580 KB
testcase_16 AC 41 ms
59,816 KB
testcase_17 AC 36 ms
53,580 KB
testcase_18 AC 37 ms
53,580 KB
testcase_19 AC 37 ms
53,580 KB
testcase_20 AC 42 ms
59,816 KB
testcase_21 AC 37 ms
53,580 KB
testcase_22 AC 37 ms
53,580 KB
testcase_23 AC 36 ms
53,580 KB
testcase_24 AC 40 ms
59,680 KB
testcase_25 WA -
testcase_26 AC 37 ms
53,516 KB
testcase_27 AC 93 ms
82,184 KB
testcase_28 AC 85 ms
80,372 KB
testcase_29 AC 75 ms
76,916 KB
testcase_30 WA -
testcase_31 AC 86 ms
80,368 KB
testcase_32 AC 49 ms
63,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

p, q = map(int, input().split())
if p > q:
    print(0)
    exit()

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