Cod sursa(job #3359607)

Utilizator theodix_1Tiroiu Theodor Alexandru theodix_1 Data 30 iunie 2026 21:47:11
Problema Numerele lui Stirling Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.88 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("stirling.in");
ofstream fout("stirling.out");
const int MOD = 98999;
const int MAX = 205;
long long s[MAX][MAX];
long long S[MAX][MAX];
void precalculare()
{
    s[0][0] = 1;
    S[0][0] = 1;
    for(int n = 1; n <= 200; n++)
        for(int m = 1; m <= n; m++)
        {
            s[n][m] = (s[n - 1][m - 1] - (n - 1) * s[n - 1][m]) % MOD;
            S[n][m] = (S[n - 1][m - 1] + m *  S[n - 1][m]) % MOD;
        }
}

int main()
{
    precalculare();
    int t;
    fin >> t;
    while(t--)
    {
        int x, n, m;
        fin >> x >> n >> m;
        if(m > n || m < 0 || n < 0)
        {
            fout << 0 << "\n";
            continue;
        }
        if(x == 1)
            fout << s[n][m] << "\n";
        else
            fout << S[n][m] << "\n";
    }
    return 0;
}