結果

問題 No.2125 Inverse Sum
コンテスト
ユーザー gr1msl3y
提出日時 2022-11-26 11:05:51
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 121 ms / 2,000 ms
+ 345µs
コード長 494 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 99 ms
コンパイル使用メモリ 81,152 KB
実行使用メモリ 99,060 KB
最終ジャッジ日時 2026-09-09 01:18:51
合計ジャッジ時間 3,915 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from math import gcd
P, Q = map(int, input().split())
g = gcd(P, Q)
P //= g
Q //= g
div_Q = set()
for i in range(1, int(Q**0.5)+1):
    if Q % i == 0:
        div_Q.add(i)
        div_Q.add(Q//i)

S = set()
for s in div_Q:
    for t in div_Q:
        S.add(s*t)

S = sorted(list(S))
ans = []
for s in S:
    n = (s+Q)//P
    if P*n-Q != s:
        continue
    t = Q**2//s
    m = (t+Q)//P
    if P*m-Q != t:
        continue
    ans.append([n, m])

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