Tap here to switch tabs
Problem
Submissions

Problem: Sum of Compatible Numbers in Range I

Try to solve the Sum of Compatible Numbers in Range I problem.

Statement

You are given two integers n and k.

An integer x is defined as compatible with n if the bitwise AND operation between n and x equals 00 (that is, n & x == 0).

Return the sum of all positive integers x in the range [max⁡(1,n−k),n+k][\max(1, n - k), n + k] that are compatible with n. If no such integers exist, return 00.

Constraints:

  • 1≤1 \le n ≤100\le 100

  • 1≤1 \le k ≤100\le 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Sum of Compatible Numbers in Range I

Try to solve the Sum of Compatible Numbers in Range I problem.

Statement

You are given two integers n and k.

An integer x is defined as compatible with n if the bitwise AND operation between n and x equals 00 (that is, n & x == 0).

Return the sum of all positive integers x in the range [max⁡(1,n−k),n+k][\max(1, n - k), n + k] that are compatible with n. If no such integers exist, return 00.

Constraints:

  • 1≤1 \le n ≤100\le 100

  • 1≤1 \le k ≤100\le 100