This page is still under construction.

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

Farey Sequence Length

Time limit1sMemory limit256 MB

Summary
Compute 1 plus the sum of Euler totient values up to N for each of up to 10000 data sets.
Level

Medium4 of 10

Topics
Number theory, Prefix sum, Math
Solved
No attempts yet

Problem

For a positive integer NN, collect every fraction a/ba/b with 0≤a≤b≤N0 \le a \le b \le N and gcd⁡(a,b)=1\gcd(a, b) = 1, then list them from smallest to largest. That list is the Farey sequence of order NN.

For example, the Farey sequence of order 6 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

Write a program that computes the length of the Farey sequence of order NN, that is, how many fractions it holds.

Input

The first line contains the number of data sets PP (1≤P≤100001 \le P \le 10000). The data sets are independent of each other and are all processed the same way.

Each of the next PP lines holds one data set: the data set number KK (1≤K≤100001 \le K \le 10000) and the order NN (2≤N≤100002 \le N \le 10000) of the Farey sequence whose length is wanted, separated by one space.

Output

Print one line per data set. Each line holds the data set number KK, one space, and the length of the Farey sequence of order NN as a decimal integer.

Examples3

  1. Example 1

    Input
    4
    1 6
    2 15
    3 57
    4 9999
    
    Expected output
    1 13
    2 73
    3 1001
    4 30393487
    
  2. Example 2

    Input
    1
    1 2
    
    Expected output
    1 3
    
  3. Example 3

    Input
    11
    1 2
    2 3
    3 4
    4 5
    5 6
    6 7
    7 8
    8 9
    9 10
    10 11
    11 12
    
    Expected output
    1 3
    2 5
    3 7
    4 11
    5 13
    6 19
    7 23
    8 29
    9 33
    10 43
    11 47