human
Write me a code to count numbers from range whose prime factors are only 2 and 3 using Arrays and the other steps required given the following:
Count numbers from range whose prime factors are only 2 and 3 using Arrays | Set 2 | Function which will calculate the elements in the given range.
Store the current power of 2.
Store the current power of 3.
power23 [ ] will store pairwise product of elements of power2 and power3 that are <= r.
Insert in power23 ] [ ] only if mul <= r.
Store the required answer.
Print the result.
Driver code"
Solution in Python:
assistant
#Here is code to count numbers from range whose prime factors are only 2 and 3 using Arrays and the other steps required.
 def calc_ans ( l , r ) :
	power2 = [ ] ; power3 = [ ] ;
	mul2 = 1 ;
	while ( mul2 <= r ) :
		power2 . append ( mul2 ) ;
		mul2 *= 2 ;
	mul3 = 1 ;
	while ( mul3 <= r ) :
		power3 . append ( mul3 ) ;
		mul3 *= 3 ;
	power23 = [ ] ;
	for x in range ( len ( power2 ) ) :
		for y in range ( len ( power3 ) ) :
			mul = power2 [ x ] * power3 [ y ] ;
			if ( mul == 1 ) :
				continue ;
			if ( mul <= r ) :
				power23 . append ( mul ) ;
	ans = 0 ;
	for x in power23 :
		if ( x >= l and x <= r ) :
			ans += 1 ;
	print ( ans ) ;
if __name__ == " _ _ main _ _ " :
	l = 1 ; r = 10 ;
	calc_ans ( l , r ) ;