結果

問題 No.2417 Div Count
コンテスト
ユーザー Kyoro ID
提出日時 2023-08-12 14:31:35
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 1,178 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 549 ms
コンパイル使用メモリ 20,832 KB
実行使用メモリ 20,996 KB
最終ジャッジ日時 2026-05-14 00:43:49
合計ジャッジ時間 13,017 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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