結果

問題 No.2125 Inverse Sum
ユーザー 👑 KazunKazun
提出日時 2022-11-18 21:38:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,362 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 81,760 KB
実行使用メモリ 81,764 KB
最終ジャッジ日時 2023-10-20 06:24:56
合計ジャッジ時間 3,137 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,624 KB
testcase_01 AC 38 ms
53,624 KB
testcase_02 AC 38 ms
53,624 KB
testcase_03 AC 38 ms
53,624 KB
testcase_04 AC 38 ms
53,624 KB
testcase_05 AC 41 ms
53,624 KB
testcase_06 AC 38 ms
53,624 KB
testcase_07 AC 41 ms
59,540 KB
testcase_08 AC 38 ms
53,624 KB
testcase_09 AC 38 ms
53,624 KB
testcase_10 AC 39 ms
53,624 KB
testcase_11 AC 38 ms
53,624 KB
testcase_12 AC 37 ms
53,624 KB
testcase_13 AC 37 ms
53,624 KB
testcase_14 AC 42 ms
59,688 KB
testcase_15 AC 37 ms
53,624 KB
testcase_16 AC 42 ms
59,688 KB
testcase_17 AC 37 ms
53,624 KB
testcase_18 AC 37 ms
53,624 KB
testcase_19 AC 38 ms
53,624 KB
testcase_20 AC 43 ms
59,688 KB
testcase_21 AC 38 ms
53,624 KB
testcase_22 AC 39 ms
53,624 KB
testcase_23 AC 38 ms
53,624 KB
testcase_24 AC 42 ms
59,540 KB
testcase_25 AC 41 ms
59,540 KB
testcase_26 AC 37 ms
53,624 KB
testcase_27 AC 95 ms
81,764 KB
testcase_28 AC 88 ms
80,304 KB
testcase_29 AC 75 ms
76,896 KB
testcase_30 AC 37 ms
53,624 KB
testcase_31 AC 87 ms
80,308 KB
testcase_32 AC 49 ms
63,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Prime_Factorization(N):
    if N==0:
        return [[0,1]]

    if N<0:
        R=[[-1,1]]
    else:
        R=[]

    N=abs(N)

    if N&1==0:
        C=0
        while N&1==0:
            N>>=1
            C+=1
        R.append([2,C])

    if N%3==0:
        C=0
        while N%3==0:
            N//=3
            C+=1
        R.append([3,C])

    k=5
    Flag=0
    while k*k<=N:
        if N%k==0:
            C=0
            while N%k==0:
                C+=1
                N//=k
            R.append([k,C])
        k+=2+2*Flag
        Flag^=1

    if N!=1:
        R.append([N,1])

    return R

#素因数分解の結果から, 約数を全て求める.
def Divisors_from_Prime_Factor(P,sorting=False):
    X=[1]
    for p,e in P:
        q=1
        n=len(X)
        for _ in range(e):
            q*=p
            for j in range(n):
                X.append(X[j]*q)

    if sorting:
        X.sort()

    return X

def solve():
    from math import gcd

    P,Q=map(int,input().split())
    g=gcd(P,Q)
    P//=g; Q//=g

    E=[(p,2*e) for p,e in Prime_Factorization(Q)]
    Ans=[]
    for a in Divisors_from_Prime_Factor(E, True):
        if (Q+a)%P==0 and (Q+Q*Q//a)%P==0:
            Ans.append(((Q+a)//P, (Q+Q*Q//a)//P))

    print(len(Ans))
    for N,M in Ans:
        print(N,M)

#==================================================
solve()
0