Faulhaber's Triangle
Time limit1sMemory limit128 MB
Build Faulhaber's triangle row by row using the recurrence F(i,j)=i/j*F(i-1,j-1) plus the normalization that each row sums to 1, then answer queries for F(m,k) as reduced fractions.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Math, Number theory
- Solved
- No attempts yet
Problem
The sum of the -th powers of the integers from to is
which can be written as a polynomial in of degree :
For example,
The coefficients form Faulhaber's triangle:
In , the row index is counted from the top starting at , and the column index is counted from the left starting at .
Faulhaber's triangle can be built as follows:
- For , .
- is chosen so that the entries in row add up to .
Given and , write a program that computes .
Input
The first line contains the number of test cases (). Each test case is a single line containing and separated by a space, with and .
Output
For each test case, output . If the value is an integer, print it as an integer; otherwise print it as a reduced fraction in the form .