以下问题均假定输入的 n 为不超过 2^31−1 的非负整数。 当输入为 6 时,输出为( )。
#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;
}
3 3
4 2
4 3
5 2