Recursive Function z
Time limit5sMemory limit256 MB
You evaluate the recursive function at n/m by tracing its arguments into a repeating cycle and solving the linear equations exactly.
Problem
Let and define the function as follows.
Given integers , , , , , , , compute the value of .
The parameters obey these bounds.
The definition always fixes to a single value. Every parameter set in the input also satisfies .
Input
The first line has the number of functions to evaluate, between 1 and 100 inclusive. Each of the following lines gives the integer parameters of one function, separated by spaces, in the order , , , , , , .
Output
For each parameter set print the value of on its own line, rounded to exactly six digits after the decimal point. Print all six digits even when they are zero. If the rounded result is zero, print 0.000000 with no sign.