eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

The Rascal Triangle

The Rascal Triangle

The Rascal Triangle definition is similar to that of the Pascal Triangle. The rows are numbered from the top starting with \textbf{0}. Each row \textbf{n} contains \textbf{n+1} numbers indexed from \textbf{0} to \textbf{n}. Using \textbf{R(n,m)} to indicte the index \textbf{m} item in the index \textbf{n} row: \textbf{R(n,m) = 0 for n < 0 OR m < 0 OR m > n} The first and last numbers in each row (which are the same in the top row) are \textbf{1}: \textbf{R(n,0) = R(n,n) = 1} The interior values are determined by \textbf{(UpLeftEntry*UpRightEntry+1)/UpEntry} (see the parallelogram in the array below): \textbf{R(n+1, m+1) = (R(n,m) * R(n,m+1) + 1)/R(n-1,m)} \includegraphics{https://static.e-olymp.com/content/84/84af53b8888d1cfe1ae830be3f0847a6e69b1e42.jpg} Write a program which computes \textbf{R(n,m)} theelement of therow of the Rascal Triangle. \InputFile The first line of input contains a single integer \textbf{P} (\textbf{1} ≤ \textbf{P} ≤ \textbf{1000}), which is the number of data sets that follow. Each data set is a single line of input consisting of \textbf{3} space separated decimal integers. The first integer is data set number, \textbf{N}. The second integer is row number \textbf{n}, and the third integer is the index \textbf{m} within the row of the entry for which you are to find \textbf{R(n,m)} the Rascal Triangle entry (\textbf{0} ≤ \textbf{m} ≤ \textbf{n} ≤ \textbf{50000}). \OutputFile For each data set there is onr line of output. It contains the data set number \textbf{N}, followed by a single space which is then followed by thr Rascal Triangle entry \textbf{R(n,m)} accurate to the integer value.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
5
1 4 0
2 4 2
3 45678 12345
4 12345 9876
5 34567 11398
Выходные данные #1
1 1
2 5
3 411495886
4 24383845
5 264080263
Источник 2011 Greater New York Regional