結果

問題 No.2125 Inverse Sum
ユーザー pitPpitP
提出日時 2022-11-18 22:25:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 822 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 81,772 KB
実行使用メモリ 59,748 KB
最終ジャッジ日時 2023-10-20 07:18:07
合計ジャッジ時間 2,552 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,632 KB
testcase_01 AC 38 ms
53,632 KB
testcase_02 AC 41 ms
53,632 KB
testcase_03 AC 38 ms
53,632 KB
testcase_04 AC 37 ms
53,632 KB
testcase_05 WA -
testcase_06 AC 41 ms
59,600 KB
testcase_07 WA -
testcase_08 AC 37 ms
53,632 KB
testcase_09 AC 38 ms
53,632 KB
testcase_10 AC 43 ms
59,720 KB
testcase_11 WA -
testcase_12 AC 39 ms
53,632 KB
testcase_13 AC 45 ms
59,736 KB
testcase_14 AC 45 ms
59,748 KB
testcase_15 AC 45 ms
59,748 KB
testcase_16 AC 45 ms
59,744 KB
testcase_17 AC 46 ms
59,744 KB
testcase_18 AC 45 ms
59,728 KB
testcase_19 AC 46 ms
59,744 KB
testcase_20 AC 45 ms
59,736 KB
testcase_21 AC 46 ms
59,748 KB
testcase_22 AC 44 ms
59,728 KB
testcase_23 AC 43 ms
59,724 KB
testcase_24 WA -
testcase_25 AC 38 ms
53,632 KB
testcase_26 AC 37 ms
53,632 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 38 ms
53,632 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

if p > 2 * q:
    print(0)
    exit()
elif p == 2 * q:
    print(1)
    print(1,1)
    exit()
elif (p == q + 1) and (q < p < 2 * q):
    ans = []
    ans.append((1,q))
    if q != 1:
        ans.append((q,1))
    print(len(ans))
    for (n,m) in ans:
        print(n,m)
    exit()
elif p == q:
    print(1)
    print(2,2)
    exit()
elif p < q:
    nm = []
    for n in range(1,ceil(sqrt(q*g))+1):
        nume = q*g*n
        deno = p*g*n-q*g
        if (deno > 0) and (nume % deno == 0):
            m = nume//deno
            nm.append((n,m))
    ans = []
    for (n,m) in nm:
        ans.append((n,m))
        if (n != m):ans.append((m,n))
    ans.sort()
    print(len(ans))
    for (n,m) in ans:
        print(n,m)
    exit()
0