human
Give me a code to sum of array elements which are prime factors of a given number and the other steps required given the following:
Sum of array elements which are prime factors of a given number | Function to check if a number is prime or not.
Corner cases.
Check if n is a multiple of 2 or 3.
Above condition allows to check only for every 6 th number , starting from 5.
If n is a multiple of i and i + 2.
Function to find the sum of array elements which are prime factors of K.
Stores the required sum.
Traverse the given array.
If current element is a prime factor of k , add it to the sum.
Print the result.
Given arr [ ].
Store the size of the array"
Solution in Python:
assistant
#Here is code to sum of array elements which are prime factors of a given number and the other steps required.
 def isPrime ( n ) :
	if ( n <= 1 ) :
		return False
	if ( n <= 3 ) :
		return True
	if ( n % 2 == 0 or n % 3 == 0 ) :
		return False
	i = 5
	while ( i * i <= n ) :
		if ( n % i == 0 or n % ( i + 2 ) == 0 ) :
			return False
		i = i + 6
	return True
def primeFactorSum ( arr , n , k ) :
	sum = 0
	for i in range ( n ) :
		if ( k % arr [ i ] == 0 and isPrime ( arr [ i ] ) ) :
			sum = sum + arr [ i ]
	print ( sum )
arr = [ 1 , 2 , 3 , 5 , 6 , 7 , 15 ]
N = len ( arr )
K = 35
primeFactorSum ( arr , N , K )