Loading...
Searching...
No Matches
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.
namespace math for assertAlgorithm 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.
◆ main()Main function.
Definition at line 74 of file largest_power.cpp.
74 {
76 return 0;
77}
static void test()
Function for testing largestPower function. test cases and assert statement.
◆ test()Function for testing largestPower function. test cases and assert statement.
Definition at line 48 of file largest_power.cpp.
48 {
50 assert(test_case_1 == 3);
51 std::cout << "Test 1 Passed!" << std::endl;
52
54 assert(test_case_2 == 4);
55 std::cout << "Test 2 Passed!" << std::endl;
56
58 assert(test_case_3 == 6);
59 std::cout << "Test 3 Passed!" << std::endl;
60
62 assert(test_case_4 == 23);
63 std::cout << "Test 4 Passed!" << std::endl;
64
66 assert(test_case_5 == 2);
67 std::cout << "Test 5 Passed!" << std::endl;
68}
uint64_t largestPower(uint32_t n, const uint16_t &p)
Function to calculate largest power.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4