Stirling numbers of the first kind: Difference between revisions
m
Improved C++ output
(Added C solution) |
m (Improved C++ output) |
||
Line 219:
=={{header|C++}}==
{{libheader|GMP}}
<lang cpp>#include <
#include <cstdint>
#include <iomanip>
#include <iostream>
Line 227 ⟶ 228:
using integer = mpz_class;
class unsigned_stirling1 {
public:
integer get(int n, int k);
Line 235:
};
integer unsigned_stirling1::get(int n, int k) {
if (k == 0)
return n == 0 ? 1 : 0;
Line 250 ⟶ 249:
}
void print_stirling_numbers(unsigned_stirling1& s1, int n) {
for (int
std::cout << std::setw(j == 0 ? 2 : 10) << j;
std::cout << '\n';
for (int i = 0; i <= n; ++i) {
std::cout << std::setw(2) << i << ' ';
for (int j = 0; j <= i; ++j)
std::cout << std::setw(j == 0 ? 2 : 10) << s1.get(i, j);
std::cout << '\n';
}
}
int main() {
unsigned_stirling1 s1;
▲ std::cout << "Unsigned Stirling numbers of the first kind:\n";
print_stirling_numbers(s1, 12);
std::cout << "Maximum value of S1(n,k) where n == 100:\n";
integer max = 0;
for (int k = 0; k <= 100; ++k)
▲ integer s = s1.get(100, k);
std::cout << max << '\n';
return 0;
Line 280 ⟶ 277:
<pre>
Unsigned Stirling numbers of the first kind:
n/k 0 1 2 3 4 5 6 7 8 9 10 11 12
0 1
10 0 362880
11 0 3628800 10628640
12 0 39916800 120543840 150917976 105258076 45995730 13339535 2637558 357423 32670 1925 66 1
Maximum value of S1(n,k) where n == 100:
19710908747055261109287881673376044669240511161402863823515728791076863288440277983854056472903481625299174865860036734731122707870406148096000000000000000000
|