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

#GL0000190. Trừ ước nguyên tố nhỏ nhất (Divisor Subtraction)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Trừ ước nguyên tố nhỏ nhất (Divisor Subtraction)

Divisor Subtraction

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer n≥2n\ge2, repeatedly do the following until n=0n=0: choose the smallest prime divisor dd of the current positive nn, then replace nn with n−dn-d. Find the total number of subtractions. The divisor is chosen from the current value each time.

Input

The input contains nn.

Output

Print the number of subtractions.

Subtasks

  • Subtask 1 (20 points): 2≤N≤10002 \le N \le 1000.

  • Subtask 2 (30 points): 2≤N≤100000002 \le N \le 10000000.

  • Subtask 3 (50 points): 2≤N≤100000000002 \le N \le 10000000000.

Examples

Example 1

Input

5

Output

1

Explanation

The smallest prime divisor of 55 is 55 itself, so the process reaches zero in one subtraction.

Example 2

Input

4

Output

2

Explanation

The successive values are 4→2→04\to2\to0, requiring two subtractions of 22.