結果

問題 No.2125 Inverse Sum
ユーザー LyricalMaestro
提出日時 2024-12-29 13:35:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 946 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 81,968 KB
実行使用メモリ 61,352 KB
最終ジャッジ日時 2024-12-29 13:35:42
合計ジャッジ時間 3,238 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/2125

import math

def calc_gcd(A, B):
    """
    正の整数A, Bの最大公約数を計算する
    """
    a = max(A, B)
    b = min(A, B)
    while a % b > 0:
        c = a % b
        a = b
        b = c
    return b

def main():
    P, Q = map(int, input().split())

    # P, Qを互いに素な整数として解く
    gcd = calc_gcd(P, Q)
    P //= gcd
    Q //= gcd

    # Qの約数分解
    sqrt_q = int(math.sqrt(Q))
    answers = []
    for n in range(1, 2 * sqrt_q + 1):    
        l = Q - n * P
        r = -Q * n
        if abs(l) > 0 and abs(r) % abs(l) == 0:
            if r * l > 0:
                m = abs(r) // abs(l)
                if m >= 1:
                    answers.append((n, m))
                    answers.append((m, n))
    answers = set(answers)
        
    print(len(answers))
    for n, m in answers:
        print(n, m)









if __name__ == "__main__":
    main()
0