Hadamard Gate

If you know a little bit of quantum computers, this problem is: Given n Hadamard Gates in series and an input qubit, predict the measurement of the output. If you don’t know about quantum computers, keep on reading. In quantum physics, superposition principle states that if a quantum system (e.g. an electron) can be in one of two states (denoted by |0⟩ and |1⟩), it can also be in any linear superposition of those two states a|0⟩ + b|1⟩, where a and b are two complex numbers, normalized so that |a|2 + |b|2 = 1. Such a superposition, a|0⟩ + b|1⟩, is the basic unit of encoded information in quantum computers, called qubit (pronounced “cubit”). An elementary quantum operation is analogous to an elementary gate like the AND or NOT gate in classical circuit. One of the most important examples is the Hadamard gate, denoted by H, which operates on a single qubit. On input |1⟩ or |0⟩, it outputs: H(|1⟩) = √1|0⟩−√1|1⟩ 22 H(|0⟩) = √1|0⟩+√1|1⟩ 22 Due to linearity of quantum physics, the output for an arbitrary superposition a|0⟩+b|1⟩ is aH(|0⟩)+ bH (|1⟩). However, the linear superposition is the private world of the quantum system. For us to get a glimpse of its state, we must make a measurement, and when we do so, we get a single bit of information — 0 or 1. If the state is a|0⟩ + b|1⟩, then the outcome of the measurement is 0 with probability |a|2 and 1 with probability |b|2 (luckily we normalized so |a|2 + |b|2 = 1). Input The first line contains the number of test cases T (T ≤ 100). Each test case contains a single line of format ‘a0 a1 b0 b1 n’, where a0, a1, b0, b1 are real numbers with at most 4 decimal places, denoting a qubit (a0 + a1i)|0⟩ + (b0 + b1i)|1⟩, and n (1 ≤ n ≤ 106) is the number of Hadamard Gates. Output For each test case, print the probability that the measurement is 0, to 6 decimal places. Sample Input 2 1.0 0.0 0.0 0.0 1 0.017133 0.704420 0.410273 0.578943 1 Sample Output Case 1: 0.500000 Case 2: 0.914848