human
Write me a code to count of subarrays consisting of only prime numbers and the other steps required given the following:
Count of subarrays consisting of only prime numbers | Function to check if a number is prime or not ..
If n has any factor other than 1 , then n is non - prime ..
Function to return the count of subarrays made up of prime numbers only.
Stores the answer.
Stores the count of continuous prime numbers in an array.
If the current array element is prime.
Increase the count.
Update count of subarrays.
If the array ended with a continuous prime sequence.
Driver Code"
Solution in Python:
assistant
#Here is code to count of subarrays consisting of only prime numbers and the other steps required.
 def is_prime ( n ) :
	if ( n <= 1 ) :
		return 0
	i = 2
	while ( i * i <= n ) :
		if ( n % i == 0 ) :
			return 0
		i += 1
	return 1
def count_prime_subarrays ( ar , n ) :
	ans = 0
	count = 0
	for i in range ( n ) :
		if ( is_prime ( ar [ i ] ) ) :
			count += 1
		else :
			if ( count ) :
				ans += count * ( count + 1 ) // 2
				count = 0
	if ( count ) :
		ans += count * ( count + 1 ) // 2
	return ans
N = 10
ar = [ 2 , 3 , 5 , 6 , 7 , 11 , 3 , 5 , 9 , 3 ]
print ( count_prime_subarrays ( ar , N ) )