結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,372 KB
testcase_01 AC 40 ms
53,372 KB
testcase_02 AC 40 ms
53,372 KB
testcase_03 AC 40 ms
53,372 KB
testcase_04 AC 40 ms
53,372 KB
testcase_05 AC 41 ms
53,372 KB
testcase_06 AC 40 ms
53,372 KB
testcase_07 AC 44 ms
59,272 KB
testcase_08 AC 40 ms
53,372 KB
testcase_09 AC 40 ms
53,372 KB
testcase_10 AC 40 ms
53,372 KB
testcase_11 AC 40 ms
53,372 KB
testcase_12 AC 39 ms
53,372 KB
testcase_13 AC 39 ms
53,372 KB
testcase_14 AC 45 ms
59,492 KB
testcase_15 AC 39 ms
53,372 KB
testcase_16 AC 44 ms
59,516 KB
testcase_17 AC 40 ms
53,372 KB
testcase_18 AC 40 ms
53,372 KB
testcase_19 AC 40 ms
53,372 KB
testcase_20 AC 45 ms
59,516 KB
testcase_21 AC 41 ms
53,372 KB
testcase_22 AC 40 ms
53,372 KB
testcase_23 AC 40 ms
53,372 KB
testcase_24 AC 43 ms
59,272 KB
testcase_25 AC 43 ms
59,272 KB
testcase_26 AC 40 ms
53,372 KB
testcase_27 AC 88 ms
81,764 KB
testcase_28 AC 79 ms
80,384 KB
testcase_29 AC 76 ms
78,956 KB
testcase_30 AC 39 ms
53,372 KB
testcase_31 AC 78 ms
80,384 KB
testcase_32 AC 52 ms
61,428 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():
    import sys
    input=sys.stdin.readline
    write=sys.stdout.write

    P,Q=map(int,input().split())

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

    print(len(Ans))
    string=lambda x:" ".join(map(str,x))
    write("\n".join(map(string,Ans)))

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