結果
問題 |
No.2125 Inverse Sum
|
ユーザー |
|
提出日時 | 2022-11-18 23:46:24 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 836 bytes |
コンパイル時間 | 166 ms |
コンパイル使用メモリ | 82,524 KB |
実行使用メモリ | 82,944 KB |
最終ジャッジ日時 | 2024-09-20 04:12:46 |
合計ジャッジ時間 | 2,764 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 WA * 5 |
ソースコード
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)