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

#SP0000134. Tổng ít số nguyên tố phân biệt nhất (Just Primes)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tổng ít số nguyên tố phân biệt nhất (Just Primes)

Just Primes

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given a positive integer NN, represent it as a sum of pairwise distinct primes. Find the minimum possible number of prime summands.

Each prime may be used at most once. The order of summands does not matter. If no such representation exists, print -1.

Input

One line contains the positive integer NN.

Output

Print the minimum number of distinct prime summands, or -1 if impossible. The original SPOJ multi-case Case i: prefix is omitted.

Subtasks

  • Subtask 1 (20 points): 1≤N≤1001\le N\le 100.
  • Subtask 2 (30 points): 1≤N≤50001\le N\le 5000.
  • Subtask 3 (50 points): 1≤N≤500001\le N\le 50000.

Examples

Input

27

Output

3

Explanation

For N=27N=27, one prime is impossible since 2727 is composite. Two distinct primes summing to an odd number must include 22, but 27−2=2527-2=25 is composite. Three distinct primes 3,5,193,5,19 satisfy 3+5+19=273+5+19=27, so the minimum is 3.