結果

問題 No.2125 Inverse Sum
ユーザー FromBooskaFromBooska
提出日時 2023-03-06 16:47:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,228 bytes
コンパイル時間 440 ms
コンパイル使用メモリ 81,724 KB
実行使用メモリ 132,020 KB
最終ジャッジ日時 2023-10-18 05:12:03
合計ジャッジ時間 3,265 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,696 KB
testcase_01 AC 45 ms
59,816 KB
testcase_02 AC 44 ms
59,816 KB
testcase_03 AC 45 ms
59,816 KB
testcase_04 AC 44 ms
59,816 KB
testcase_05 WA -
testcase_06 AC 60 ms
70,936 KB
testcase_07 WA -
testcase_08 AC 51 ms
65,172 KB
testcase_09 AC 38 ms
53,696 KB
testcase_10 AC 62 ms
73,120 KB
testcase_11 AC 45 ms
59,816 KB
testcase_12 AC 44 ms
59,816 KB
testcase_13 AC 50 ms
62,988 KB
testcase_14 AC 59 ms
70,780 KB
testcase_15 AC 49 ms
63,580 KB
testcase_16 AC 64 ms
74,572 KB
testcase_17 WA -
testcase_18 AC 52 ms
64,728 KB
testcase_19 AC 51 ms
63,252 KB
testcase_20 AC 69 ms
74,940 KB
testcase_21 WA -
testcase_22 AC 49 ms
63,576 KB
testcase_23 AC 52 ms
64,060 KB
testcase_24 WA -
testcase_25 AC 46 ms
59,840 KB
testcase_26 AC 40 ms
53,696 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 40 ms
53,696 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 変形してQ*(M+N) = N*M*P
# gcd(P, Q)で両辺を割る
# もしP=Q=1の場合、M=N=2
# それ以外の場合、N,MはQの素因数を持つ、N+MはPの倍数
# Qの約数でNを全探索すればいい、約数だけではなく約数の倍数もありうるか

def divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

from math import gcd
P, Q = map(int, input().split())
g = gcd(P, Q)
P = P//g
Q = Q//g
if P == 1:
    print(1)
    print(Q*2, Q*2)
else:
    ans_list = []
    divs = divisors(Q)
    visited = set()
    for d in divs:
        for k in range(1, 1000):
            n = d*k
            if n in visited:
                continue
            visited.add(n)
            
            if (P*n-Q) != 0 and (n*Q)%(P*n-Q) == 0 and (n*Q)//(P*n-Q) > 0:
                if Q*(((n*Q)//(P*n-Q))+n) == P*((n*Q)//(P*n-Q))*n:
                    ans_list.append((n, (n*Q)//(P*n-Q)))
                    #print(d, k, n)

    print(len(ans_list))
    for n, m in ans_list:
        print(n, m)
0