Блог пользователя Madiyar

Автор Madiyar, 12 лет назад, По-английски

While solving Andrew Stankevich Contest 32, Problem K, I noticed that __builtin_popcount for long long doesn't work properly, I spent a lot of time to find my mistake, but when I wrote __builtin_popcount by myself it accepted.

__builtin_popcount defined only for int?

  • Проголосовать: нравится
  • +31
  • Проголосовать: не нравится

»
12 лет назад, скрыть # |
 
Проголосовать: нравится +83 Проголосовать: не нравится
  • __builtin_popcount = int
  • __builtin_popcountl = long int
  • __builtin_popcountll = long long
»
12 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится -18 Проголосовать: не нравится

What is " __builtin_popcount"? I found something. But I couldn't find all of them :(

»
12 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +22 Проголосовать: не нравится

__builtin_popcount(x) is a function in C++ returns the number of 1-bits set in an int x. In fact, "popcount" stands for "population count," so this is a function to determine how "populated" an integer is.

For example, say we have an int x with value equal to 12. 12 in binary is just 1100, and the rest of the digits are just 0's. So, __builtin_popcount(12) = 2.

»
12 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +12 Проголосовать: не нравится

Interesting fact : __builtin_popcount is slow. Can anyone tell the complexity? For a constant time bitcount use this : http://pastie.org/9412225 .Please don't ask me how it works exactly! It'd be useful to add it to your library code :)

»
7 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится -25 Проголосовать: не нравится

There is NO __builtin_popcount in c++, it's a built in function of GCC. The function prototype is as follows: int __builtin_popcount(unsigned int) It returns the numbers of set bits in an integer (the number of ones in the binary representation of the integer).

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Lol same thing happened with me in a codechef contest .. and i couldn't spot it during the whole contest

»
4 года назад, скрыть # |
 
Проголосовать: нравится -13 Проголосовать: не нравится

what is the time complexity of __builtin_popcount() which is used as cpp inbuilt function