|
Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
Algorithm to find largest x such that p^x divides n! (factorial) using Legendre's Formula. More...
#include <iostream>#include <cassert>Namespaces | |
| namespace | math |
| for std::rand | |
Functions | |
| uint64_t | math::largestPower (uint32_t n, const uint16_t &p) |
| Function to calculate largest power. More... | |
| static void | test () |
| Function for testing largestPower function. test cases and assert statement. More... | |
| int | main () |
| Main function. More... | |
Algorithm to find largest x such that p^x divides n! (factorial) using Legendre's Formula.
Given an integer n and a prime number p, the task is to find the largest x such that p^x (p raised to power x) divides n! (factorial). This will be done using Legendre's formula: x = [n/(p^1)] + [n/(p^2)] + [n/(p^3)] + \ldots + 1
| int main | ( | void | ) |
|
static |
Function for testing largestPower function. test cases and assert statement.
void