Cod sursa(job #1472876)

Utilizator al.mocanuAlexandru Mocanu al.mocanu Data 17 august 2015 22:51:10
Problema Numerele lui Stirling Scor 100
Compilator c Status done
Runda Arhiva educationala Marime 0.68 kb
#include <stdio.h>
#define R 98999
#define MAX 205

int t, n, m, i, j, tip;
long long s[MAX][MAX], S[MAX][MAX];

void stirling1(){
	s[0][0] = 1;
	for(i = 1; i <= 200; i++)
		for(j = 1; j <= 200; j++)
			s[i][j] = (s[i - 1][j - 1] - (i - 1) * s[i - 1][j]) % R;
}

void stirling2(){
	S[0][0] = 1;
	for(i = 1; i <= 200; i++)
		for(j = 1; j <= 200; j++)
			S[i][j] = (S[i - 1][j - 1] + j * S[i - 1][j]) % R;
}

int main(){
	freopen("stirling.in", "r", stdin);
	freopen("stirling.out", "w", stdout);
	scanf("%d", &t);
	stirling1();
	stirling2();
	for(i = 0; i < t; i++){
		scanf("%d%d%d", &tip, &n, &m);
		if(tip == 1)
			printf("%lld\n", s[n][m]);
		else
			printf("%lld\n", S[n][m]);
	}
	return 0;
}