Under construction

Still being built. Things may change

gCube (Small)

Time limit5sMemory limit512 MB

Summary
Compute the geometric mean of each queried subarray and print it with nine digits after the decimal point.
Level

Medium4 of 10

Topics
Math
Solved
No attempts yet

Problem

A DD-dimensional cube has DD dimensions of equal length. DD is any positive integer, so a 1-dimensional cube is a line segment, a 2-dimensional cube is a square, and a 4-dimensional cube is a hypercube. A DD-dimensional cuboid also has DD dimensions, but their lengths may differ.

You are given an NN-dimensional cuboid. Its dimensions are numbered 0,1,2,…,N−10, 1, 2, \ldots, N-1 in order, and dimension ii has length aia_i. Answer MM queries of the following form.

  1. Take the consecutive dimensions from the LiL_i-th one to the RiR_i-th one, inclusive.
  2. Build a DD-dimensional cuboid from those dimensions, where D=Ri−Li+1D = R_i - L_i + 1. For example, if Li=3L_i = 3 and Ri=6R_i = 6, the new cuboid uses dimensions 3, 4, 5, and 6.
  3. Reshape that cuboid into a DD-dimensional cube with exactly the same volume, and report the edge length of the cube.

Every query of a test case uses the same original NN-dimensional cuboid.

Input

The first line has the number of test cases TT. The TT test cases follow.

Each test case begins with a line holding two integers NN and MM, the number of dimensions and the number of queries. The next line has NN positive integers a0,a1,…,aN−1a_0, a_1, \ldots, a_{N-1}, the lengths of the dimensions in order. Each of the next MM lines has two integers LiL_i and RiR_i, the range of dimensions used by the ii-th query.

Output

For each test case, print one line "Case #x:", where x is the number of the test case starting from 1. Then print MM lines, where the ii-th line has the edge length for the ii-th query.

The edge length for a query is (∏j=LiRiaj)1/D\left(\prod_{j=L_i}^{R_i} a_j\right)^{1/D} with D=Ri−Li+1D = R_i - L_i + 1. Print it with exactly 9 digits after the decimal point, rounding the exact value half up at the ninth decimal place. The root is usually irrational and the product reaches 109010^{90}, so compute it precisely enough that the ninth decimal digit is correct. Always print at least one digit before the decimal point and never print a plus sign.

Constraints

  • 1≤T≤1001 \le T \le 100
  • 1≤N≤101 \le N \le 10
  • 1≤M≤101 \le M \le 10
  • 1≤ai≤1091 \le a_i \le 10^9
  • 0≤Li≤Ri<N0 \le L_i \le R_i < N

Examples4

  1. Example 1

    Input
    2
    2 2
    1 4
    0 0
    0 1
    3 2
    1 2 3
    0 1
    1 2
    
    Expected output
    Case #1:
    1.000000000
    2.000000000
    Case #2:
    1.414213562
    2.449489743
    
  2. Example 2

    Input
    1
    1 1
    1
    0 0
    
    Expected output
    Case #1:
    1.000000000
    
  3. Example 3

    Input
    2
    3 3
    8 8 8
    0 2
    0 1
    2 2
    3 4
    2 4 8
    0 2
    0 0
    1 2
    0 1
    
    Expected output
    Case #1:
    8.000000000
    8.000000000
    8.000000000
    Case #2:
    4.000000000
    2.000000000
    5.656854249
    2.828427125
    
  4. Example 4

    Input
    2
    5 5
    2 3 5 7 11
    0 4
    0 1
    1 3
    2 4
    3 4
    4 6
    9 9 9 9
    0 3
    0 1
    1 2
    2 3
    0 2
    2 2
    
    Expected output
    Case #1:
    4.706763706
    2.449489743
    4.717693980
    7.274786349
    8.774964387
    Case #2:
    9.000000000
    9.000000000
    9.000000000
    9.000000000
    9.000000000
    9.000000000