human
Minimum length of subsequence having unit GCD | Function that finds the prime factors of a number.
To store the prime factor.
2 s that divide n.
N must be odd at this point Skip one element.
Update the prime factor.
If n is a prime number greater than 2.
Function that finds the shortest subsequence.
Check if the prime factor of first number , is also the prime factor of the rest numbers in array.
Set corresponding bit of prime factor to 1 , it means both these numbers have the same prime factor.
If no states encountered so far continue for this combination of bits.
Update this state with minimum ways to reach this state.
Function that print the minimum length of subsequence.
Find the prime factors of the first number.
Initialize the array with maximum steps , size of the array + 1 for instance.
Total number of set bits is equal to the total number of prime factors.
Indicates there is one way to reach the number under consideration.
State 0 corresponds to gcd of 1.
If not found such subsequence then print " - 1".
Else print the length.
Driver Code.
Given array arr [ ].
Function Call"
Solution in Python:

=====
Can you provide a code to minimum length of subsequence having unit GCD and the other steps required?
assistant
#Here is code to minimum length of subsequence having unit GCD and the other steps required.
 def findPrimeFactors ( n ) :
	primeFactors = [ 0 for i in range ( 9 ) ]
	j = 0
	if ( n % 2 == 0 ) :
		primeFactors [ j ] = 2
		j += 1
		while ( n % 2 == 0 ) :
			n >>= 1
	i = 3
	while ( i * i <= n ) :
		if ( n % i == 0 ) :
			primeFactors [ j ] = i
			j += 1
			while ( n % i == 0 ) :
				n //= i
		i += 2
	if ( n > 2 ) :
		primeFactors [ j ] = n
		j += 1
	for i in range ( 0 , j + 1 ) :
		primeFactors [ i ] = 0
	return primeFactors
def findShortestSubsequence ( dp , a , index , primeFactors ) :
	n = len ( a )
	for j in range ( index , n ) :
		bitmask = 0
		for p in range ( len ( primeFactors ) ) :
			if ( primeFactors [ p ] != 0 and a [ j ] % primeFactors [ p ] == 0 ) :
				bitmask ^= ( 1 << p )
		for i in range ( len ( dp ) ) :
			if ( dp [ i ] == n + 1 ) :
				continue
			dp [ bitmask & i ] = min ( dp [ bitmask & i ] , dp [ i ] + 1 )
def printMinimumLength ( a ) :
	mn = len ( a ) + 1
	for i in range ( len ( a ) - 1 ) :
		primeFactors = findPrimeFactors ( a [ i ] )
		n = len ( primeFactors )
		dp = [ 0 for i in range ( 1 << n ) ]
		dp = [ len ( a ) + 1 for i in range ( len ( dp ) ) ]
		setBits = ( 1 << n ) - 1
		dp [ setBits ] = 1
		findShortestSubsequence ( dp , a , i + 1 , primeFactors )
		mn = min ( dp [ 0 ] , mn )
	if ( mn == len ( a ) + 1 ) :
		print ( - 1 )
	else :
		print ( mn )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 2 , 6 , 12 , 3 ]
	printMinimumLength ( arr )