#GL0000259. Độ dài dãy Farey (Farey Sequence Length)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Độ dài dãy Farey (Farey Sequence Length)
Farey Sequence Length
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
The Farey sequence of order consists of all reduced fractions between and inclusive, where , listed in increasing order. A fraction is reduced if . Every rational value appears exactly once.
For instance, the Farey sequence of order is , and its length is .
Given , determine the length of the Farey sequence of order , including both endpoints and .
Input
- One line containing an integer , the order of the Farey sequence.
Output
- Print a single integer equal to the number of fractions in the Farey sequence of order .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
6
Output
13
Explanation
For , the fractions in increasing order are , , , , , , , , , , , , and . Thus the length is .
Example 2
Input
15
Output
73
Explanation
The sequence includes the two endpoints and . For each denominator from through , exactly numerators yield reduced proper fractions. The values are ; their sum is . Including the endpoints gives .