Tap here to switch tabs
Problem
Submissions

Problem: Sum of Compatible Numbers in Range I

Sum of Compatible Numbers in Range I gives n and k and asks for the sum of positive integers from n minus k up to n plus k whose bitwise AND with n is zero, or zero if none qualify.

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

Sum of Compatible Numbers in Range I gives n and k and asks for the sum of positive integers from n minus k up to n plus k whose bitwise AND with n is zero, or zero if none qualify.

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