結果

問題 No.2051 Divide
ユーザー lam6er
提出日時 2025-03-20 21:16:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 692 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 82,652 KB
実行使用メモリ 59,248 KB
最終ジャッジ日時 2025-03-20 21:17:34
合計ジャッジ時間 1,813 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

A, B = map(int, input().split())

if A % B != 0:
    print(0)
else:
    m = A // B

    def count_factors(n):
        if n == 0:
            return 0
        res = 1
        # Handle even factor 2
        exp = 0
        while n % 2 == 0:
            exp += 1
            n //= 2
        if exp > 0:
            res *= (exp + 1)
        # Handle odd factors
        i = 3
        while i * i <= n:
            exp = 0
            while n % i == 0:
                exp += 1
                n //= i
            if exp > 0:
                res *= (exp + 1)
            i += 2
        # Remaining prime factor
        if n > 1:
            res *= 2
        return res

    print(count_factors(m))
0