这是 2026-10-23 的上一版评测(LiveCodeBench 最新 35 题)。最新的阶梯评测见 首页。

题目 › 3801

Count Beautiful Numbers

LeetCode 周赛 441 · 2025-03-15 · 困难

各位数字之积能被各位数字之和整除的正整数称为美丽数;求 [l, r] 内美丽数的个数。

要点:数位 DP:含 0 时积为 0,必满足;否则积为 2ᵃ3ᵇ5ᶜ7ᵈ,状态有限;暴力枚举超时。

查看原题

结果

Kimi K3.1 ProKimi

✓

通过

  • 函数调用,官方测试全部通过判题
  • 6.4k输出 token(含思考) ↓
  • 99 秒延迟 ↓
  • 0.11 秒(最快)最慢测试的 CPU 时间 ↓
  • 26 MB峰值内存 ↓
  • 6Pylint 问题 ↓
  • 7.39Pylint 得分 ↑
  • 3圈复杂度 ↓
  • 61.9可维护性指数 ↑
  • 37有效行
  • 2SonarQube 问题 ↓

DeepSeek-V4.1-FlashDS-Flash

✓

通过

  • 函数调用,官方测试全部通过判题
  • 3.8k输出 token(含思考) ↓
  • 22 秒延迟 ↓
  • 0.11 秒最慢测试的 CPU 时间 ↓
  • 26 MB峰值内存 ↓
  • 6Pylint 问题 ↓
  • 7.39Pylint 得分 ↑
  • 3圈复杂度 ↓
  • 51.6可维护性指数 ↑
  • 25有效行
  • 2SonarQube 问题 ↓

DeepSeek-V4-ProDS-Pro

✓

通过

  • 函数调用,官方测试全部通过判题
  • 66.3k输出 token(含思考) ↓
  • 474 秒延迟 ↓
  • 0.93 秒(8.3×)最慢测试的 CPU 时间 ↓
  • 18 MB峰值内存 ↓
  • 14Pylint 问题 ↓
  • 8.21Pylint 得分 ↑
  • 5圈复杂度 ↓
  • 55.0可维护性指数 ↑
  • 81有效行
  • 4SonarQube 问题 ↓

↑ 越大越好,↓ 越小越好,有效行只描述代码长短。CPU 时间与内存只统计能区分性能的题(最慢答案扣除进程启动后仍 ≥ 0.1 秒),括号内为相对最快者的倍数(≥ 2 时标出)。静态质量按 arXiv:2610.19167 的口径(见 原理)。判题方法见 原理 › 判题。

代码

Kimi K3.1 Pro · 48 行
from functools import lru_cache


class Solution:
    def beautifulNumbers(self, l: int, r: int) -> int:
        def count_up_to(x: int) -> int:
            if x <= 0:
                return 0

            digits = [int(c) for c in str(x)]
            n = len(digits)

            @lru_cache(None)
            def dfs(
                pos: int,
                digit_sum: int,
                digit_product: int,
                started: bool,
                tight: bool,
            ) -> int:
                if pos == n:
                    if not started:
                        return 0
                    return int(digit_product % digit_sum == 0)

                limit = digits[pos] if tight else 9
                total = 0

                for d in range(limit + 1):
                    next_tight = tight and d == digits[pos]

                    if not started and d == 0:
                        # Leading zero: the number has not started yet.
                        total += dfs(pos + 1, 0, 1, False, next_tight)
                    else:
                        total += dfs(
                            pos + 1,
                            digit_sum + d,
                            digit_product * d,
                            True,
                            next_tight,
                        )

                return total

            return dfs(0, 0, 1, False, True)

        return count_up_to(r) - count_up_to(l - 1)