LeetCode Entry

3622. Check Divisibility by Digit Sum and Product

22.08.2026 easy 2026 kotlin rust

Is divisible by sum + product of digits

3622. Check Divisibility by Digit Sum and Product easy substack youtube

https://dmitrysamoylenko.com/leetcode/

22.08.2026.webp

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/1459

Problem TLDR

Is divisible by sum + product of digits

Intuition

Brute force.

However, as a joke, this is accepted too

    fun checkDivisibility(n: Int)='0' in "$n" && n%
    "$n".sumOf{it-'0'}<1||n in 19..99 step 10||n in setOf(42,111111,794556,979968)

The problem has an interesting distribution pattern of the product influence to divisibility. Code_Generated_Image (2).png

Approach

  • just do brute forcec

Complexity

  • Time complexity: \(O(logn)\)

  • Space complexity: \(O(1)\)

Code

    fun checkDivisibility(n: Int) = 1>n%"$n"
    .map {it-'0'}.run{sum()+reduce{a,b->a*b}}
    pub fn check_divisibility(n: i32) -> bool {
        let (mut t, mut s, mut p) = (n, 0, 1);
        while t > 0 { s += t % 10; p *= t % 10; t /= 10 }
        n % (s + p) == 0
    }

Comments