Hacker News new | ask | show | jobs
by hairtuq 2308 days ago
Here's a version that at least for 64 bit might be faster:

  bool isPerfect(uint64_t x) {
        int ctz = __builtin_ctzll(x);
        return ((0x40051056 >> ctz) & 1) && ((x >> ctz) + 1) == (uint64_t(1) << (ctz + 1));
  }