#SP0000255. Những đoạn có tổng nguyên tố (Prime Segments)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những đoạn có tổng nguyên tố (Prime Segments)
Prime Segments
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a sequence of positive integers . A contiguous subarray is determined by two positions with .
A subarray is a prime segment if the sum of its elements is a prime number (an integer greater than with exactly two positive divisors, and itself).
Count all index pairs such that is prime. Different index pairs are distinct even if their sums are the same.
Input
The first line contains the length .
The second line contains exactly integers in sequence order.
Output
Print a single 64-bit integer: the number of contiguous subarrays having a prime sum. No modulo is applied.
Subtasks
- Subtask 1 (20 points): ; for every ; .
- Subtask 2 (30 points): ; for every ; .
- Subtask 3 (50 points): ; for every ; .
Examples
Input
4
1 2 3 4
Output
5
Explanation
For the sequence , exactly five subarrays qualify:
- : .
- : .
- : .
- : .
- : .
All other subarrays have nonprime sums. Therefore the answer is .