PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000259. Độ dài dãy Farey (Farey Sequence Length)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Độ 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 NN consists of all reduced fractions a/ba/b between 00 and 11 inclusive, where 0≤a≤b≤N0\le a\le b\le N, listed in increasing order. A fraction a/ba/b is reduced if gcd⁡(a,b)=1\gcd(a,b)=1. Every rational value appears exactly once.

For instance, the Farey sequence of order 33 is 0/1,1/3,1/2,2/3,1/10/1, 1/3, 1/2, 2/3, 1/1, and its length is 55.

Given NN, determine the length of the Farey sequence of order NN, including both endpoints 0/10/1 and 1/11/1.

Input

  • One line containing an integer NN, the order of the Farey sequence.

Output

  • Print a single integer equal to the number of fractions in the Farey sequence of order NN.

Subtasks

  • Subtask 1 (20 points): 2≤N≤302\le N\le 30.
  • Subtask 2 (30 points): 2≤N≤15002\le N\le 1500.
  • Subtask 3 (50 points): 2≤N≤100002\le N\le 10000.

Examples

Example 1

Input

6

Output

13

Explanation

For N=6N=6, the fractions in increasing order are 0/10/1, 1/61/6, 1/51/5, 1/41/4, 1/31/3, 2/52/5, 1/21/2, 3/53/5, 2/32/3, 3/43/4, 4/54/5, 5/65/6, and 1/11/1. Thus the length is 1313.

Example 2

Input

15

Output

73

Explanation

The sequence includes the two endpoints 0/10/1 and 1/11/1. For each denominator bb from 22 through 1515, exactly φ(b)\varphi(b) numerators yield reduced proper fractions. The values φ(2),…,φ(15)\varphi(2),\ldots,\varphi(15) are 1,2,2,4,2,6,4,6,4,10,4,12,6,81,2,2,4,2,6,4,6,4,10,4,12,6,8; their sum is 7171. Including the endpoints gives 7373.