Question regarding __builtin_popcount

I was solving a question on codeforces. I tried using __builtin_popcount(x) to count the number of active bits, but that method gave a WA. When I just changed __builtin_popcount(x) to loop counter, it gave AC.

Do you know why was there this behavior?

Please note that I was doing exor, so I don’t think overflow would be the reason (personal opinion)

My AC submission link
My WA submission link

A diff checker Link to compare two codes. (Left one is WA and the right one is AC)

1 Like

use __builtin_popcountll(x) is for long long.
__builtin_popcount(x) only works for int.

5 Likes

More people need to post their “one AC one WA” codes like this :slight_smile:

5 Likes

Yes, we should do our best to ease the work of people helping us. :smile:

1 Like

Thank you. I was so confused on what is happening. :smile:

Use __builtin_popcountll(x) for long long .It should work fine

Thank you :smile: