TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Algorithm to find largest x such that p^x divides n! (factorial) using Legendre's Formula. More...
#include <cassert>
#include <cstdint>
#include <iostream>
Go to the source code of this file.
Namespaces | |
namespace | math |
for assert | |
Functions | |
uint64_t | math::largestPower (uint32_t n, const uint16_t &p) |
Function to calculate largest power. | |
static void | test () |
Function for testing largestPower function. test cases and assert statement. | |
int | main () |
Main function. | |
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)]
Definition in file largest_power.cpp.
int main | ( | void | ) |
Main function.
Definition at line 74 of file largest_power.cpp.
|
static |
Function for testing largestPower function. test cases and assert statement.
void
Definition at line 48 of file largest_power.cpp.