This page is still under construction.

Parts of this page are still being built. What you see may change.

Farey Sequence Sum

Time limit1sMemory limit256 MB

Summary
Given N, compute the sum of consecutive denominator ratios in the N-th Farey sequence and print it as a reduced fraction.
Level

Hard8 of 10

Topics
Number theory, Math
Solved
No attempts yet

Problem

For a positive integer NN, take every irreducible fraction a/ba/b with 0<a≤b0 < a \le b and 1≤b≤N1 \le b \le N, together with 0/10/1 and 1/11/1, and sort them in increasing order. The result is the NN-th Farey sequence.

For example, the 6th Farey sequence is:

0/1, 1/6, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 5/6, 1/10/1,\ 1/6,\ 1/5,\ 1/4,\ 1/3,\ 2/5,\ 1/2,\ 3/5,\ 2/3,\ 3/4,\ 4/5,\ 5/6,\ 1/1

Writing down only the denominators of the NN-th Farey sequence, in order, gives a sequence b1,b2,…,bKb_1, b_2, \dots, b_K of length KK. The Farey sum is the total of bi/bi+1b_i / b_{i+1} over i=1i = 1 through K−1K-1.

∑i=1K−1bibi+1\sum_{i=1}^{K-1} \frac{b_i}{b_{i+1}}

The sum for the 6th Farey sequence works out like this:

16+65+54+43+35+52+25+53+34+45+56+61=352\frac{1}{6} + \frac{6}{5} + \frac{5}{4} + \frac{4}{3} + \frac{3}{5} + \frac{5}{2} + \frac{2}{5} + \frac{5}{3} + \frac{3}{4} + \frac{4}{5} + \frac{5}{6} + \frac{6}{1} = \frac{35}{2}

Given NN, compute the sum of the NN-th Farey sequence.

Input

The first line holds the number of test cases PP. (1≤P≤100001 \le P \le 10000)

Each of the next PP lines holds a test case number TT and the value NN described above, separated by one space. (1≤T≤100001 \le T \le 10000, 2≤N≤100002 \le N \le 10000)

Output

For each test case, print the test case number given in the input and the Farey sum on one line, separated by one space. Reprint the number exactly as it appears in the input, and keep the lines in input order.

Always write the sum as a reduced fraction in the form numerator/denominator. If the reduced denominator is 1, print only the numerator.

Hint

The (N+1)(N+1)-th Farey sequence contains every fraction of the NN-th one, plus as many new fractions as there are positive integers up to NN that are coprime with N+1N+1.

Examples2

  1. Example 1

    Input
    4
    1 6
    2 15
    3 57
    4 9999
    
    Expected output
    1 35/2
    2 215/2
    3 2999/2
    4 91180457/2
    
  2. Example 2

    Input
    1
    1 2
    
    Expected output
    1 5/2