結果

問題 No.2125 Inverse Sum
ユーザー とりゐとりゐ
提出日時 2022-11-17 20:47:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 205 ms / 2,000 ms
コード長 709 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 81,712 KB
実行使用メモリ 97,436 KB
最終ジャッジ日時 2023-10-20 05:49:15
合計ジャッジ時間 3,355 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,152 KB
testcase_01 AC 37 ms
52,156 KB
testcase_02 AC 37 ms
52,144 KB
testcase_03 AC 37 ms
52,144 KB
testcase_04 AC 36 ms
52,152 KB
testcase_05 AC 44 ms
59,580 KB
testcase_06 AC 43 ms
58,296 KB
testcase_07 AC 45 ms
57,364 KB
testcase_08 AC 40 ms
57,416 KB
testcase_09 AC 38 ms
52,152 KB
testcase_10 AC 44 ms
58,288 KB
testcase_11 AC 37 ms
52,164 KB
testcase_12 AC 38 ms
52,152 KB
testcase_13 AC 42 ms
57,412 KB
testcase_14 AC 44 ms
59,164 KB
testcase_15 AC 41 ms
57,520 KB
testcase_16 AC 45 ms
59,396 KB
testcase_17 AC 41 ms
57,524 KB
testcase_18 AC 42 ms
58,184 KB
testcase_19 AC 40 ms
57,448 KB
testcase_20 AC 47 ms
59,972 KB
testcase_21 AC 40 ms
57,456 KB
testcase_22 AC 40 ms
57,504 KB
testcase_23 AC 39 ms
57,524 KB
testcase_24 AC 39 ms
57,360 KB
testcase_25 AC 39 ms
57,368 KB
testcase_26 AC 38 ms
52,144 KB
testcase_27 AC 205 ms
97,436 KB
testcase_28 AC 179 ms
90,624 KB
testcase_29 AC 90 ms
81,840 KB
testcase_30 AC 36 ms
53,720 KB
testcase_31 AC 181 ms
90,624 KB
testcase_32 AC 132 ms
67,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def divisors(n):
  lower,upper=[],[]
  i=1
  while i*i<=n:
    if n%i==0:
      lower.append(i)
      if i!=n//i:
        upper.append(n//i)
    i+=1
  return lower+upper[::-1]

def divisors2(n):
  # n^2 の約数列挙
  s=set()
  d=divisors(n)
  for i in d:
    for j in d:
      if n*n%(i*j)==0:
        s.add(i*j)
  s=sorted(list(s))
  return s


def solve(p,q):
  #(pa-q)*(pb-q)=q^2 を解く
  ans=[]
  check=set()
  for i in divisors2(q):
    j=q**2//i
    if (i+q)%p==0:
      if (i+q)//p not in check:
        ans.append([(i+q)//p,(j+q)//p])
        check.add((i+q)//p)
  print(len(ans))
  for i in ans:
    print(*i)

import math
p,q=map(int,input().split())
solve(p//math.gcd(p,q),q//math.gcd(p,q))
0