|
Algorithms_in_C++
1.0.0
Set of algorithms implemented in C++.
|
for std::vector More...
Functions | |
| uint64_t | largestPower (uint32_t n, const uint16_t &p) |
| Function to calculate largest power. More... | |
| uint64_t | lcmSum (const uint16_t &num) |
| bool | magic_number (const uint64_t &n) |
| uint64_t | power (uint64_t a, uint64_t b, uint64_t c) |
| This function calculates a raised to exponent b under modulo c using modular exponentiation. More... | |
| template<class T > | |
| T | n_choose_r (T n, T r) |
| This is the function implementation of \( \binom{n}{r} \). More... | |
| void | power_of_two (int n) |
| Function to test above algorithm. More... | |
| uint64_t | binomialCoeffSum (uint64_t n) |
for std::vector
Math algorithms.
for std::cout
for IO operations
for io operations
for assert
for assert for std::cin and std::cout
Mathematical algorithms
Mathematical algorithms
for assert
Mathematical algorithms
for assert for io operations
Mathematical algorithms
Mathematical algorithms
| uint64_t math::binomialCoeffSum | ( | uint64_t | n | ) |
| uint64_t math::largestPower | ( | uint32_t | n, |
| const uint16_t & | p | ||
| ) |
| uint64_t math::lcmSum | ( | const uint16_t & | num | ) |
Function to compute sum of euler totients in sumOfEulerTotient vector
| num | input number |
| bool math::magic_number | ( | const uint64_t & | n | ) |
Function to check if the given number is magic number or not.
| n | number to be checked. |
| T math::n_choose_r | ( | T | n, |
| T | r | ||
| ) |
This is the function implementation of \( \binom{n}{r} \).
We are calculating the ans with iterations instead of calculating three different factorials. Also, we are using the fact that \( \frac{n!}{r! (n-r)!} = \frac{(n - r + 1) \times \cdots \times n}{1 \times \cdots \times r} \)
| T | Only for integer types such as long, int_64 etc |
| n | \( n \) in \( \binom{n}{r} \) |
| r | \( r \) in \( \binom{n}{r} \) |
| uint64_t math::power | ( | uint64_t | a, |
| uint64_t | b, | ||
| uint64_t | c | ||
| ) |
This function calculates a raised to exponent b under modulo c using modular exponentiation.
| a | integer base |
| b | unsigned integer exponent |
| c | integer modulo |
Initialize the answer to be returned
Update a if it is more than or equal to c
In case a is divisible by c;
If b is odd, multiply a with answer
b must be even now
b = b/2
| void math::power_of_two | ( | int | n | ) |
Function to test above algorithm.
| n | description |
This function finds whether a number is power of 2 or not
| n | value for which we want to check prints the result, as "Yes, the number n is a power of 2" or "No, the number is not a power of 2" without quotes |
result stores the bitwise and of n and n-1