Menu
CoddyTech

Tina 和她的位赋值

Coddy 位运算 课程的第 14 课,共 17 课。

challenge icon

挑战

中等

蒂娜老师给学生一个正整数 <strong>x</strong>。作为作业,学生需要找到满足以下两个条件的最小正整数 <strong>y</strong>:

  • x AND y > 0 
  • x XOR y > 0

举个例子, 

x = 1:满足上述两个条件的最小整数是 3,因为:

  • 1 <strong>AND</strong> 3 = 1 > 0
  • 1 <strong>XOR</strong> 3 = 2 > 0。

完成函数 MinPositiveY() ,找到 y 的值并返回。

亲手试试

#include <cmath>
using namespace std;

int MinPositiveY(int x) {
    // 在这里编写代码
}

位运算中的所有课

自己练习: C++ 在线编译器