Stirling numbers of the second kind: Difference between revisions

m
Improved C++ output
m (C bug fix)
m (Improved C++ output)
Line 211:
using integer = mpz_class;
 
class stirling2 {
{
public:
integer get(int n, int k);
Line 219 ⟶ 218:
};
 
integer stirling2::get(int n, int k) {
{
if (k == n)
return 1;
Line 234 ⟶ 232:
}
 
void print_stirling_numbers(stirling2& s2, int n) {
std::cout << "Stirling numbers of the second kind:\nnn/k";
{
for (int ij = 0; ij <= n; ++ij) {
std::cout << std::setw(j == 0 ? 2 : 8) << 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 : 8) << s2.get(i, j);
std::cout << '\n';
}
}
 
int main() {
{
stirling2 s2;
std::cout << "Stirling numbers of the second kind:\n";
print_stirling_numbers(s2, 12);
std::cout << "Maximum value of S2(n,k) where n == 100:\n";
integer max = 0;
for (int k = 0; k <= 100; ++k)
integer smax = std::max(max, s2.get(100, k));
{
integer s = s2.get(100, k);
if (s > max)
max = s;
}
std::cout << max << '\n';
return 0;
Line 264 ⟶ 260:
<pre>
Stirling numbers of the second kind:
n/k 0 1 2 3 4 5 6 7 8 9 10 11 12
1
0 1
1 0 1 1
2 0 1 3 1
3 0 1 7 63 1
4 0 1 15 7 25 106 1
5 0 1 3115 9025 65 1510 1
6 0 1 63 31 301 90 350 14065 2115 1
7 0 1 127 63 966 301 1701 1050350 266140 2821 1
8 0 1 255 127 3025 7770966 69511701 26461050 462266 3628 1
9 0 1 511 255 9330 3025 34105 7770 42525 228276951 58802646 750462 4536 1
10 0 0 1 1 511 1023 9330 28501 34105 145750 24673042525 179487 22827 63987 5880 11880 1155750 5545 1
11 0 1 20471023 28501 86526 145750 611501 1379400246730 1323652 179487 627396 15902763987 2227511880 17051155 6655 1
12 0 1 2047 86526 611501 1379400 1323652 627396 159027 22275 1705 66 1
Maximum value of S2(n,k) where n == 100:
7769730053598745155212806612787584787397878128370115840974992570102386086289805848025074822404843545178960761551674
1,777

edits