Skip to content

Commit 0016ade

Browse files
authored
Update factorial_top_down_dp.cpp
added __uint128_t for handling fixed-width integer types
1 parent 6f121ec commit 0016ade

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

dynamic_programming/factorial_top_down_dp.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@
1313

1414
#include <iostream>
1515
#include <cassert> // For test cases
16-
#include <cstdint> // For uint64_t
1716
#include <array>
1817
/// Array to store computed factorials for memoization
19-
std::array<uint64_t, 1000> memo{0};
18+
std::array<__uint128_t, 1000> memo{0};
2019

2120
/**
2221
* @brief Computes the factorial of a non-negative integer using recursion and memoization.
2322
* @param n The integer whose factorial is to be computed
2423
* @returns The factorial of n
2524
*/
26-
long long fact_rec(int n) {
25+
__uint128_t fact_rec(__uint128_t n) {
2726
if (n == 0) return 1; // Base case: 0! = 1
2827
if (memo[n] != 0) return memo[n]; // Return already computed value
2928
memo[n] = n * fact_rec(n - 1); // Store and return the computed value

0 commit comments

Comments
 (0)