import std.conv, std.functional, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.range, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } int N; long[] P; void main() { try { for (; ; ) { const numCases = readInt(); foreach (caseId; 0 .. numCases) { N = readInt(); P = new long[N]; foreach (i; 0 .. N) { P[i] = readLong(); } debug { writeln("P = ", P); } auto prodP = new real[1 << N]; auto probZero = new real[1 << N]; auto probNonZero = new real[1 << N]; foreach (a; 0 .. 1 << N) { prodP[a] = 1.0; probZero[a] = 1.0; probNonZero[a] = 1.0; foreach (i; 0 .. N) { if ((a >> i) & 1) { prodP[a] *= cast(real)(P[i]); probZero[a] *= cast(real)(1) / cast(real)(P[i]); probNonZero[a] *= cast(real)(P[i] - 1) / cast(real)(P[i]); } } } auto E = new int[N]; foreach (i; 0 .. N) { E[i] = bsf(P[i] - 1); } const maxE = E.maxElement; auto probPlus = new real[][](1 << N, maxE + 1); auto probMinus = new real[][](1 << N, maxE + 1); foreach (a; 0 .. 1 << N) { probPlus[a][] = 1.0; probMinus[a][] = 1.0; foreach (k; 0 .. maxE + 1) { foreach (i; 0 .. N) { if ((a >> i) & 1) { probPlus[a][k] *= (cast(real)((P[i] - 1) >> E[i] << min(k, E[i])) / cast(real)(P[i])); probMinus[a][k] *= (k < E[i]) ? (cast(real)((P[i] - 1) >> E[i] << k) / cast(real)(P[i])) : 0.0; } } } } auto dp = new real[1 << N]; foreach (a; 1 .. 1 << N) { if (a & (a - 1)) { debug { if (N <= 3) { writeln("a = ", a); } } real nmr = 0.0, dnm = 1.0; { // P[i] | r for all i debug { if (N <= 3) { writeln(" ", prodP[a] * probZero[a]); } } dnm -= probZero[a]; } for (int b = a; --b &= a; ) { // P[i] | r for i in b debug { if (N <= 3) { writeln(" b = ", b, ": ", prodP[a] * probZero[b] * probNonZero[a ^ b]); } } nmr += probZero[b] * probNonZero[a ^ b] * (dp[b] + dp[a ^ b]); } { // r^(2^k) == -1 for all i real prob = probPlus[a][0]; foreach (k; 0 .. maxE + 1) { prob += probMinus[a][k]; } debug { if (N <= 3) { writeln(" ", prodP[a] * prob); } } dnm -= prob; } for (int b = a; --b &= a; ) { // r^(2^k) == -1 (P[i]) for i in b real prob = 0.0; foreach (k; 0 .. maxE + 1) { prob += probMinus[b][k] * probPlus[a ^ b][k]; } debug { if (N <= 3) { writeln(" b = ", b, ": ", prodP[a] * prob); } } nmr += prob * (dp[b] + dp[a ^ b]); } dp[a] = (1.0 + nmr) / dnm; } else { dp[a] = 1.0; } } writefln("%.9f", dp[$ - 1]); } } } catch (EOFException e) { } }