human
Print the nodes with a prime degree in given Prufer sequence of a Tree | Function to create Sieve to check primes.
False here indicates that it is not prime.
If prime [ p ] is not changed , then it is a prime.
Update all multiples of p , set them to non - prime.
Function to print the nodes with prime degree in the tree whose Prufer sequence is given.
Hash - table to mark the degree of every node.
Initially let all the degrees be 1.
Increase the count of the degree.
Print the nodes with prime degree.
Driver Code"
How can the above be solved in Python?
 What is a code to print the nodes with a prime degree in given Prufer sequence of a Tree and the other steps required?
assistant
#Here is code to print the nodes with a prime degree in given Prufer sequence of a Tree and the other steps required.
 def SieveOfEratosthenes ( prime , p_size ) :
	prime [ 0 ] = False
	prime [ 1 ] = False
	p = 2
	while ( p * p <= p_size ) :
		if ( prime [ p ] ) :
			for i in range ( p * 2 , p_size + 1 , p ) :
				prime [ i ] = False
		p += 1
def PrimeDegreeNodes ( prufer , n ) :
	nodes = n + 2
	prime = [ True ] * ( nodes + 1 )
	SieveOfEratosthenes ( prime , nodes + 1 )
	degree = [ 0 ] * ( n + 2 + 1 ) ;
	for i in range ( 1 , nodes + 1 ) :
		degree [ i ] = 1 ;
	for i in range ( 0 , n ) :
		degree [ prufer [ i ] ] += 1
	for i in range ( 1 , nodes + 1 ) :
		if prime [ degree [ i ] ] :
			print ( i , end = ' ▁ ' )
if __name__ == ' _ _ main _ _ ' :
	a = [ 4 , 1 , 3 , 4 ]
	n = len ( a )
	PrimeDegreeNodes ( a , n )