raybbian's CP Algos

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub raybbian/comp-programming

:heavy_check_mark: algo/utils/bits.h

Depends on

Required by

Verified with

Code

#pragma once
#include "algo/common.h"

namespace algo::utils {

// Number of 1 bits in x
constexpr int popcnt(int64_t x) {
    return __builtin_popcountll(x);
}
// floor(log2(x)); -1 for x = 0
constexpr int lg2(uint64_t x) {
    return std::bit_width(x) - 1;
}

} // namespace algo::utils
#line 2 "algo/common.h"
#ifndef PREPROCESS
#include <bits/stdc++.h>
#include <cassert>
#endif

// Declared here so `using namespace algo;` works with no other includes.
namespace algo {}
#line 3 "algo/utils/bits.h"

namespace algo::utils {

// Number of 1 bits in x
constexpr int popcnt(int64_t x) {
    return __builtin_popcountll(x);
}
// floor(log2(x)); -1 for x = 0
constexpr int lg2(uint64_t x) {
    return std::bit_width(x) - 1;
}

} // namespace algo::utils
Back to top page