二个整数的二进制比较,以及区间个数计算

这篇博客讨论了一个关于30位无符号整数的问题,要求找出所有符合给定三个整数A、B、C中任意一个的整数个数。博主提供了一个解决方案,并指出需要优化算法以提高性能。
摘要由CSDN通过智能技术生成

发现了一道题, 因为有点意思,于是便记录下来,共同研究

题目如下: 

In this problem we consider unsigned 30-bit integers, i.e. all integers B such that 0 ≤ B < 230.

We say that integer A conforms to integer B if, in all positions where B has bits set to 1, A has corresponding bits set to 1.

For example:

  • 00 0000 1111 0111 1101 1110 0000 1111(BIN) = 16,244,239 conforms to
    00 0000 1100 0110 1101 1110 0000 0001(BIN) = 13,032,961, but
  • 11 0000 1101 0111 0000 1010 0000 0101(BIN) = 819,399,173 does not conform to
    00 0000 1001 0110 0011 0011 0000 1111(BIN) = 9,843,471.

Write a function:

def solution(A, B, C)

that, given three unsigned 30-bit integers A, B and C, returns the number of unsigned 30-bit integers conforming to at least one of the given integers.

For example, for integers:

  • A = 11 1111 1111 1111
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值