結果

問題 No.2417 Div Count
ユーザー Kyoro ID
提出日時 2023-08-12 14:31:35
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,178 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-11-19 19:55:32
合計ジャッジ時間 3,483 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import logging
import math
input = sys.stdin.readline
logger = logging.getLogger(__name__)


def read():
    N, K = map(int, input().strip().split())
    return N, K


def prime_factorization(n: int):
    if n == 1:
        return ([1], [1])
    factors = []
    counts = []
    for i in range(2, math.isqrt(n)+1):
        if i * i > n:
            break
        if n % i == 0:
            factors.append(i)
            n //= i
            count = 1
            while n % i == 0:
                n //= i
                count += 1
            counts.append(count)
    if n > 1:
        factors.append(n)
        counts.append(1)
    return factors, counts


def solve(N, K):
    n = N - K
    factors, counts = prime_factorization(n)
    n_factors = len(factors)
    ans = []

    def dfs(i, a):
        if i >= n_factors:
            if a > K:
                ans.append(a)
            return
        for count in range(counts[i]+1):
            dfs(i+1, a * (factors[i] ** count))
    
    dfs(0, 1)
    return len(ans)
    

if __name__ == "__main__":
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))
0