Expectation

Time limit2sMemory limit64 MB

Summary
Compute the exact expected value (as a reduced fraction) of the XOR of two independent uniform random integers in [0, n-1), for up to 1000 values of n up to 1e9.
Level

Medium6 of 10

Topics
Bit manipulation, Math, Combinatorics
Solved
No attempts yet

Problem

Eric built a simple scheme for generating random integers. Given an integer nn, it outputs a uniformly random integer between 00 and n−1n-1 inclusive. For example, when n=3n = 3 it returns 00, 11, or 22, each with probability 1/31/3.

Eric now wants a more elaborate scheme. He takes two independent copies of this generator and feeds their outputs into a bitwise XOR gate, which returns the bitwise exclusive or of its two inputs. His friend Nick is curious about the expectation of the result, and they would like you to compute it.

Recall that the expectation of a random variable is its average value. For a variable ξ\xi taking non-negative integer values it is

E[ξ]=∑i=0∞i⋅pi\mathbf{E}[\xi] = \sum_{i=0}^{\infty} i \cdot p_i

where pip_i is the probability that ξ\xi equals ii.

The exact expectation is always a rational number, so you must report it exactly rather than as a rounded decimal.

Input

The first line contains the number of test cases kk (1≤k≤10001 \le k \le 1000). Each of the next kk lines contains a single integer nn (1≤n≤1091 \le n \le 10^9).

Output

For each test case, output the exact expected value of the XOR of the two generators' outputs as an irreducible fraction p/qp/q, where q≥1q \ge 1 and gcd⁡(p,q)=1\gcd(p, q) = 1. If the value is an integer, still write it with denominator 11 (for example, 0/10/1). Print the answer for each test case on its own line.

Examples4

  1. Example 1

    Input
    2
    3
    4
    
    Expected output
    4/3
    3/2
    
  2. Example 2

    Input
    1
    1
    
    Expected output
    0/1
    
  3. Example 3

    Input
    1
    2
    
    Expected output
    1/2
    
  4. Example 4

    Input
    3
    5
    6
    8
    
    Expected output
    68/25
    19/6
    7/2