Distinct rational numbers
Time limit2sMemory limit512 MB
Count distinct values of a/b with 0 <= a <= b <= N, i.e. fractions in [0,1] with reduced denominator at most N.
- Level
Medium5 of 10
- Topics
- Math, Number theory, Combinatorics, Prefix sum
- Solved
- No attempts yet
Problem
You are given a positive integer . Count how many distinct values the fraction takes over all integers and with . A denominator cannot be , so is at least . Fractions with the same value are counted once. For example, and have the same value, so they count as one.
Input
The first line contains the number of test cases (). Each of the next lines contains one integer ().
Output
For each test case, print the number of distinct rational numbers on its own line.