36 lines
866 B
C++
36 lines
866 B
C++
#ifndef INCLUDE_GUARD_INT_UTILS_H
|
|
#define INCLUDE_GUARD_INT_UTILS_H
|
|
|
|
#include <cstdint> // uint32_t, uint64_t
|
|
|
|
/**
|
|
* Integer logarithm, the biggest power `p` such that `2^p <= x`.
|
|
*/
|
|
int ilog2(uint64_t x);
|
|
|
|
/**
|
|
* Integer Square root of `y`, that is `ceiling(sqrt(y))`
|
|
*/
|
|
uint64_t isqrt(uint64_t x);
|
|
|
|
/**
|
|
* Inverse to the triangular numbers
|
|
*
|
|
* Given a positive number `x = p (p + 1) / 2` it computes `p` if possible.
|
|
* In case there is no positive integer solution `0` is returned.
|
|
*
|
|
* Note: this follows immediately from the quadratic equation.
|
|
*/
|
|
uint32_t invTriag(uint32_t x);
|
|
|
|
/**
|
|
* Number of sub-sets (including empty set) of max-size
|
|
*
|
|
* It computes, with `binom` beeing the binomial coefficient, the following sum
|
|
*
|
|
* sum_{i = 0}^k binom(n, i)
|
|
*/
|
|
uint64_t nrSubSets(uint64_t n, uint64_t k);
|
|
|
|
#endif /* INCLUDE_GUARD_INT_UTILS_H */
|