Cod sursa(job #2973310)

Utilizator zoabaZob Alexandru Mihai zoaba Data 31 ianuarie 2023 18:37:48
Problema Numerele lui Stirling Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <fstream>

using namespace std;
ifstream fin("stirling.in");
ofstream fout("stirling.out");
int a[202][202];
int b[202][202];
int const n = 200;
const int MOD = 98999;
void speta1()
{
    int i,j;
    a[1][1] = 1;
    for(i=2;i<n;++i)
    {
        for(j=1;j<=i;++j)
        {
            a[i][j] = (a[i-1][j-1] - (i-1) *a[i-1][j])%MOD;
        }
    }
}
void speta2()
{
    int i,j;
    b[1][1] = 1;
    for(i=2;i<=n;++i)
    {
        for(j=1;j<=i;++j)
        {
            b[i][j] = (b[i-1][j -1] + j * b[i-1][j])%MOD;
        }
    }
}
int main()
{
    int t;
    fin >> t;
    speta1();
    speta2();
    while(t--)
    {
        int x, N, M;
        fin >> x >> N >> M;
        if(x == 1)
        {
            fout << a[N][M] << '\n';
        }
        else if(x == 2)
        {
            fout << b[N][M] << '\n';
        }
    }
    return 0;
}