結果

問題 No.2125 Inverse Sum
ユーザー flygonflygon
提出日時 2022-11-19 02:14:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 674 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 81,748 KB
実行使用メモリ 87,236 KB
最終ジャッジ日時 2023-10-20 10:34:37
合計ジャッジ時間 3,437 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,508 KB
testcase_01 AC 39 ms
53,712 KB
testcase_02 AC 39 ms
53,712 KB
testcase_03 AC 39 ms
53,712 KB
testcase_04 AC 41 ms
53,712 KB
testcase_05 AC 51 ms
59,488 KB
testcase_06 AC 43 ms
59,488 KB
testcase_07 AC 43 ms
57,440 KB
testcase_08 AC 43 ms
57,440 KB
testcase_09 AC 39 ms
53,508 KB
testcase_10 AC 43 ms
59,488 KB
testcase_11 AC 40 ms
53,712 KB
testcase_12 AC 39 ms
53,712 KB
testcase_13 AC 42 ms
57,440 KB
testcase_14 AC 47 ms
60,240 KB
testcase_15 AC 43 ms
59,488 KB
testcase_16 AC 46 ms
60,240 KB
testcase_17 AC 43 ms
59,488 KB
testcase_18 AC 43 ms
59,488 KB
testcase_19 AC 42 ms
57,440 KB
testcase_20 AC 47 ms
60,240 KB
testcase_21 AC 43 ms
59,488 KB
testcase_22 AC 43 ms
59,488 KB
testcase_23 AC 43 ms
59,488 KB
testcase_24 AC 43 ms
57,440 KB
testcase_25 AC 43 ms
57,440 KB
testcase_26 AC 40 ms
53,508 KB
testcase_27 AC 210 ms
87,236 KB
testcase_28 AC 174 ms
83,276 KB
testcase_29 AC 125 ms
79,144 KB
testcase_30 AC 39 ms
53,508 KB
testcase_31 AC 174 ms
83,276 KB
testcase_32 AC 50 ms
63,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

p,q = map(int,input().split())
from math import gcd
g = gcd(p,q)
p //= g
q //= g

def fact(n):
  l = []
  tmp = n
  for i in range(2,int(pow(n,0.5))+1):
    if tmp % i == 0:
      cnt = 0
      while tmp % i == 0:
        cnt += 1
        tmp //= i
      l.append([i,cnt])
  if tmp != 1:
    l.append([tmp,1])
  return l


f = fact(q)
l = [1]
for i,j in f:
  tmp = l[::1]
  l = []
  for k in range(2*j+1):
    for now in tmp:
      l.append(now*pow(i, k))
qq = q*q
ans = set()
for i in l:
  j = qq//i
  i += q
  j += q
  if i % p == 0 and j % p == 0:  
    ans.add((i//p, j//p))
    ans.add((j//p,i//p))
ans = sorted(list(ans))
print(len(ans))
for i, j in ans:
  print(i,j)
0