以下问题均假定输入的 n 为不超过 2^31−1 的非负整数。当输入为 3 时,程序输出为 3 3。( )
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int x = 1, y = 1;
while (n > 0) {
if (n % 2 == 0) {
++x;
} else {
++x;
++y;
}
n = n / 2;
}
cout << x << ' ' << y << endl;
return 0;
}
正确
错误