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

#SP0000236. Ghép cặp táo của Jzzhu (Jzzhu and Apples)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Ghép cặp táo của Jzzhu (Jzzhu and Apples)

Jzzhu and Apples

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Jzzhu has nn apples numbered 11 through nn. He wants to divide some of them into groups of exactly two apples. Apples xx and yy may be paired only when gcd⁡(x,y)>1\gcd(x,y)>1, meaning their numbers share a prime divisor.

Each apple may belong to at most one group; unpaired apples are permitted.

Find the maximum number of groups and output any pairing achieving that maximum. If several optimal pairings exist, you may output any one of them.

Input

The only line contains an integer nn.

Output

Print mm, the maximum number of groups, on the first line. Each of the following mm lines contains two apple indices x,yx,y in a group. Each number in [1,n][1,n] may appear at most once, and gcd⁡(x,y)>1\gcd(x,y)>1 must hold.

Subtasks

  • Subtask 1 (20 points): 1≤n≤141\le n\le14.

  • Subtask 2 (30 points): 1≤n≤10001\le n\le1000.

  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5.

Examples

Input

6

Output

2
6 3
2 4

Explanation

For n=6n=6, the apples are numbered 1,2,3,4,5,61,2,3,4,5,6. Pair (6,3)(6,3) is valid as gcd⁡(6,3)=3>1\gcd(6,3)=3>1; pair (2,4)(2,4) is valid as gcd⁡(2,4)=2>1\gcd(2,4)=2>1. The four numbers are distinct. Of the remaining apples 11 and 55, apple 11 cannot be paired with any number, and 55 has no other multiple of 55 up to 66. Thus at most two pairs are possible, and the sample attains this maximum.