human
Online Queries for GCD of array after divide operations | Returns the gcd after all updates in the array.
Function to calculate gcd of onine queries.
Stores the gcd of the initial array elements.
calculates the gcd.
performing online queries.
index is 1 based.
divide the array element.
calculates the current gcd.
Print the gcd after each step.
Driver code"
Solution in Python:
 Give me a code to online Queries for GCD of array after divide operations and the other steps required?
assistant
#Here is code to online Queries for GCD of array after divide operations and the other steps required.
 def gcd ( a , b ) :
	if a == 0 :
		return b
	return gcd ( b % a , a )
def print_gcd_online ( n , m , query , arr ) :
	max_gcd = 0
	for i in range ( 0 , n ) :
		max_gcd = gcd ( max_gcd , arr [ i ] )
	for i in range ( 0 , m ) :
		query [ i ] [ 0 ] -= 1
		arr [ query [ i ] [ 0 ] ] //= query [ i ] [ 1 ]
		max_gcd = gcd ( arr [ query [ i ] [ 0 ] ] , max_gcd )
		print ( max_gcd )
if __name__ == " _ _ main _ _ " :
	n , m = 3 , 3
	query = [ [ 1 , 3 ] , [ 3 , 12 ] , [ 2 , 4 ] ]
	arr = [ 36 , 24 , 72 ]
	print_gcd_online ( n , m , query , arr )