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 <cstdintalgorithm>
#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) {
std::cout << "Unsigned Stirling numbers of the first kind:\nnn/k";
{
for (int ij = 0; ij <= n; ++ij) {
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 smax = std::max(max, s1.get(100, k));
{
integer s = s1.get(100, k);
if (s > max)
max = s;
}
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
1
0 1
0 1
1 0 1 1
2 0 2 31 1
3 0 6 112 63 1
4 0 24 6 50 11 35 106 1
5 0 120 24 274 22550 8535 1510 1
6 0 720 120 1764 274 1624 225 735 17585 2115 1
7 0 5040 720 13068 1764 13132 1624 6769 1960735 322175 2821 1
8 0 40320 5040 109584 13068 118124 13132 67284 224496769 45361960 546322 3628 1
9 0 362880 40320 1026576 109584 1172700 118124 723680 26932567284 6327322449 94504536 870546 4536 1
10 0 362880 0 36288001026576 10628640 1172700 12753576 8409500723680 3416930 269325 902055 63273 157773 9450 18150 1320870 5545 1
11 0 3628800 10628640 0 3991680012753576 120543840 150917976 1052580768409500 45995730 3416930 13339535 2637558902055 357423157773 3267018150 19251320 6655 1
12 0 39916800 120543840 150917976 105258076 45995730 13339535 2637558 357423 32670 1925 66 1
Maximum value of S1(n,k) where n == 100:
19710908747055261109287881673376044669240511161402863823515728791076863288440277983854056472903481625299174865860036734731122707870406148096000000000000000000
1,777

edits