Cod sursa(job #2965844)

Utilizator ezluciPirtac Eduard ezluci Data 16 ianuarie 2023 12:41:43
Problema Numerele lui Stirling Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.21 kb
using namespace std;
#ifdef EZ
   #include "./ez/ez.h"
   const string FILE_NAME = "test";
#else
   #include <bits/stdc++.h>
   const string FILE_NAME = "stirling";
#endif
#define mp make_pair
#define mt make_tuple
#define ll long long
#define pb push_back
#define fi first
#define se second
#define cin fin
#define cout fout
ifstream fin (FILE_NAME + ".in");
ofstream fout (FILE_NAME + ".out");

const int MOD = 98999;
const int nMAX = 200;

int s1[nMAX + 1][nMAX + 1];
int s2[nMAX + 1][nMAX + 1];


void genS1()
{
   for (int i = 1; i <= nMAX; ++i)
   {
      int j = 1;
      if (i == 1)
         s1[1][1] = 1,  j = 2;
      
      for (; j <= i; ++j)
         s1[i][j] = (s1[i-1][j-1] + 1LL * (i-1) * s1[i-1][j]) % MOD;
   }
}


void genS2()
{
   s2[0][0] = 1;
   for (int i = 1; i <= nMAX; ++i)
   {
      for (int j = 1; j <= i; ++j)
         s2[i][j] = (s2[i-1][j-1] + 1LL * j * s2[i-1][j]) % MOD;
   }
}


int main()
{
   genS1();
   genS2();

   int t;
   cin >> t;
   while (t--)
   {
      int x, n, m;
      cin >> x >> n >> m;

      if (x == 1)
         if (n+m & 1)
            cout << -s1[n][m] << '\n';
         else
            cout << s1[n][m] << '\n';
      else if (x == 2)
         cout << s2[n][m] << '\n';
   }
}