#K80737. Subarray with Prime Sum
Subarray with Prime Sum
Subarray with Prime Sum
You are given an array of integers. Your task is to determine whether there exists a contiguous subarray (a sequence of one or more consecutive elements) such that the sum of its elements is a prime number.
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. In our approach, we consider a number \( n \) as follows: if \( n \le 1 \) it is not prime; if \( n \le 3 \) it is prime; otherwise, we check divisibility by 2 and 3, and then test for divisibility up to \( \sqrt{n} \) by iterating from 5 in increments of 6.
If there is any contiguous subarray with a sum that is prime, print YES
. Otherwise, print NO
.
inputFormat
The input is read from standard input (stdin). The first line contains a single integer ( n ) representing the number of elements in the array. The second line contains ( n ) space-separated integers.
outputFormat
Output a single line to standard output (stdout) containing either YES
or NO
depending on whether there exists a subarray whose sum is a prime number.## sample
5
1 2 3 4 5
YES