結果
| 問題 |
No.2125 Inverse Sum
|
| コンテスト | |
| ユーザー |
FromBooska
|
| 提出日時 | 2023-03-06 16:07:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 959 bytes |
| コンパイル時間 | 168 ms |
| コンパイル使用メモリ | 82,424 KB |
| 実行使用メモリ | 59,648 KB |
| 最終ジャッジ日時 | 2024-09-18 01:51:24 |
| 合計ジャッジ時間 | 2,650 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 WA * 11 |
ソースコード
# 変形して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 and Q == 1:
print(1)
print(2, 2)
else:
ans_list = []
divs = divisors(Q)
for n in divs:
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(len(ans_list))
for n, m in ans_list:
print(n, m)
FromBooska