0% found this document useful (0 votes)
259 views1 page

Stirling Numbers C++ Code

This C++ program defines functions to generate Stirling numbers of the first and second kind in arrays s and S up to size 200. It then takes in test cases with an ID, n and m and outputs either the Stirling number of the first or second kind from the appropriate array based on the ID.

Uploaded by

toncuvasile
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
259 views1 page

Stirling Numbers C++ Code

This C++ program defines functions to generate Stirling numbers of the first and second kind in arrays s and S up to size 200. It then takes in test cases with an ID, n and m and outputs either the Stirling number of the first or second kind from the appropriate array based on the ID.

Uploaded by

toncuvasile
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include<cstdio>

#include<iostream>
using namespace std;
const int MOD=98999;
int s[201][201], S[201][201];
void generate_s(){
s[1][1]=1;
for(int i=2;i<=200;i++)
for(int j=1;j<=200;j++)
s[i][j]=( s[i-1][j-1] - (i-1)*(s[i-1][j]) )%MOD;
}
void generate_S(){
S[1][1]=1;
for(int i=2;i<=200;i++)
for(int j=1;j<=200;j++)
S[i][j]=( S[i-1][j-1] - j*(S[i-1][j]) )%MOD;
}
int main(){
freopen("stirling.in","r",stdin);
freopen("stirling.out","w",stdout);
generate_S();
generate_s();
int T;
cin>>T;
int id,n,m;
for(;T;T--){
cin>>id>>n>>m;
if(id==1) cout<<s[n][m]<<"\n";
else cout<<S[n][m]<<"\n";
}
}

You might also like