Cod sursa(job #2981636)

Utilizator raresgherasaRares Gherasa raresgherasa Data 18 februarie 2023 13:20:36
Problema Numerele lui Stirling Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("stirling.in");
ofstream fout ("stirling.out");

const int mod = 98999;
const int kN = 1e3 + 5;

int s1[kN][kN], s2[kN][kN];

int main(){
   ios_base::sync_with_stdio(false);

   s1[0][0] = s2[0][0] = 1;
   for (int i = 1; i < kN; i++){
      for (int j = 1; j <= i; j++){
         s1[i][j] = (s1[i - 1][j - 1] - ((i - 1) * s1[i - 1][j]) % mod) % mod;
         s2[i][j] = (s2[i - 1][j - 1] + (j * (s2[i - 1][j])) % mod) % mod;
      }
   }
   int t; fin >> t;
   while (t--){
      int tip, x, y;
      fin >> tip >> x >> y;
      fout << (tip == 1 ? s1[x][y] : s2[x][y]) << '\n';
   }
}