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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 , 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 .
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): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
27
Output
3
Explanation
For , one prime is impossible since is composite. Two distinct primes summing to an odd number must include , but is composite. Three distinct primes satisfy , so the minimum is 3.