Cod sursa(job #1558939)

Utilizator georgeliviuPereteanu George georgeliviu Data 29 decembrie 2015 20:05:15
Problema Numerele lui Stirling Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.05 kb
#include <cstdio>

using namespace std;

const int n = 201 , modulo = 98999 ;
int s[202][202] , S[202][202] , i , j ;

void s_mic()
{
    s[1][1] = 1 ;
    for ( i = 2 ; i < n ; i++ )
    {
        for ( j = 1 ; j <= i ; j++ )
        {
            s[i][j] = ( s[i-1][j-1] - ( i - 1 ) * s[i-1][j] ) % modulo ;
        }
    }
}

void S_mare()
{
    S[1][1] = 1 ;
    for ( i = 2 ; i < n ; i++ )
    {
        for ( j = 1 ; j <= i ; j++ )
        {
            S[i][j] = ( S[i-1][j-1] + j * S[i-1][j] ) % modulo ;
        }
    }
}

int main()
{
    freopen("stirling.in","r",stdin);
    freopen("stirling.out","w",stdout);
    int x , y , speta , t;
    s_mic();
    S_mare();
    scanf("%d",&t);
    for ( int h = 1 ; h <= t ; h++ )
    {
        scanf("%d %d %d",&speta,&x,&y) ;
        {
            if ( speta == 1 )
            {
                printf("%d\n",s[x][y]);
            }
            if ( speta == 2 )
            {
                printf("%d\n",S[x][y]);
            }
        }
    }
    return 0 ;
}