eolymp
bolt
Try our new interface for solving problems
Problems

Faulhaber`s Triangle

Faulhaber`s Triangle

The sum of the \textbf{m}-th powers of the first \textbf{n} integers \includegraphics{https://static.e-olymp.com/content/a7/a76a3a084178168dee81ee28896daaa537e42e6f.jpg} can be written as a polynomial of degree \textbf{m+1} in \textbf{n}: \includegraphics{https://static.e-olymp.com/content/eb/eba9e8a02e697adc83f815fbd8db8ca1c920381e.jpg} For example: \textbf{S(n, 1) = (1 + ... + n) = (1/2) * n2 + (1/2) * n} \textbf{S(n, 2) = (1 + ... + n2) = (1/3) * n3 + (1/2) * n2 + (1/6) * n} \textbf{S(n, 3) = (1 +...+ n3) = (1/4) * n4 + (1/2) * n3) + (1/4) * n2} \textbf{S(n, 4) = (1 +...+ n4) = (1/5) * n5 + (1/2) * n4) + (1/3) * n3 - (1/30) * n} The coefficients \textbf{F(m, k)} of these formulas form Faulhaber's Triangle: \includegraphics{https://static.e-olymp.com/content/dc/dcb0bf610580584fcd8a4e7a9d2c89be2b9488e8.jpg} where rows \textbf{m} start with \textbf{0} (at the top) and columns \textbf{k} go from \textbf{1} to \textbf{m+1} Each row of Faulhaber's Triangle can be computed from the previous row by: a) The element in row \textbf{i} and column \textbf{j} (\textbf{j} > \textbf{1}) is \textbf{(i/j) * (}\textit{\textbf{the element above left}}\textbf{)}; that is: \textbf{F(i, j) = (i/j) * F(i-1, j-1)} b) The first element in each row \textbf{F(i, 1)} is chosen so the sum of the elements in the row is \textbf{1}. Write a program to find entries in Faulhaber's Triangle as decimal fractions in lowest terms. \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 should be processed identically and independently. Each data set consists of a single line of input consisting of three space separated decimal integers. The first integer is the data set number. The second integer is row number \textbf{m}, and the third integer is the index \textbf{k} within the row of the entry for which you are to find \textbf{F(m, k)}, the Faulhaber's Triangle entry (\textbf{0} ≤ \textbf{m} ≤ \textbf{400}, \textbf{1} ≤ \textbf{k} ≤ \textbf{m+1}). \OutputFile For each data set there is a single line of output. It contains the data set number, followed by a single space which is then followed by either the value if it is an integer \textbf{OR} by the numerator of the entry, a forward slash and the denominator of the entry.
Time limit 1 second
Memory limit 32 MiB
Input example #1
4
1 4 1
2 4 3
3 86 79
4 400 401
Output example #1
1 -1/30
2 1/3
3 -22388337
4 1/401