Farey Sequence Length
Time limit1sMemory limit256 MB
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 , collect every fraction with and , then list them from smallest to largest. That list is the Farey sequence of order .
For example, the Farey sequence of order 6 is
Write a program that computes the length of the Farey sequence of order , that is, how many fractions it holds.
Input
The first line contains the number of data sets (). The data sets are independent of each other and are all processed the same way.
Each of the next lines holds one data set: the data set number () and the order () 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 , one space, and the length of the Farey sequence of order as a decimal integer.