題目上有一份 code 跟你說如果 n 太大時會跑不動,叫你改造這個 code
#include <iostream>
using namespace std;
int count_it(long long n) {
int count_num = 0;
do {
count_num += n & 1;
} while (n >>= 1);
return count_num;
}
int main() {
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
cout << count_it(n) << endl;
}
return 0;
}
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up