PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000133. Tổng các số nguyên tố liên tiếp (Sum of 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 các số nguyên tố liên tiếp (Sum of Primes)
Sum of Primes
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Consider the prime numbers in increasing order: . A representation of a positive integer is a nonempty contiguous segment of this prime sequence whose sum equals .
The selected primes must be consecutive in the prime sequence, not just an arbitrary set of primes. A segment containing one prime is valid.
Count all such segments. Representations with different starting or ending positions are distinct.
Input
One line contains the integer .
Output
Print one integer: the number of valid representations of .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
41
Output
3
Explanation
For , exactly three consecutive-prime segments sum to :
- ;
- ;
- the one-element segment .
For instance, is invalid because prime lies between them. Hence the answer is 3.