Array Queries for multiply , replacements and product | vector of 1000 elements , all set to 0 ; vector of 1000 elements , all set to 0 ; Function to check number of trailing zeros in multiple of 2 ; Function to check number of trailing zeros in multiple of 5 ; Function to solve the queries received ; If the query is of typee 1. ; Counting the number of zeros in the given value of x ; The value x has been multiplied to their respective indices ; The value obtained above has been added to their respective vectors ; If the query is of typee 2. ; Counting the number of zero in the given value of x ; The value y has been replaced to their respective indices ; The value obtained above has been added to their respective vectors ; If the query is of typee 2 ; As the number of trailing zeros for each case has been found for each array element then we simply add those to the respective index to a variable ; Compare the number of zeros obtained in the multiples of five and two consider the minimum of them and add them ; Input the Size of array and number of queries ; Running the while loop for m number of queries
twos = [ 0 ] * 1000 NEW_LINE fives = [ 0 ] * 1000 NEW_LINE sum = 0 NEW_LINE def returnTwos ( val ) : NEW_LINE INDENT count = 0 NEW_LINE while ( val % 2 == 0 and val != 0 ) : NEW_LINE INDENT val = val // 2 NEW_LINE count += 1 NEW_LINE DEDENT return count NEW_LINE DEDENT def returnFives ( val ) : NEW_LINE INDENT count = 0 NEW_LINE while ( val % 5 == 0 and val != 0 ) : NEW_LINE INDENT val = val // 5 NEW_LINE count += 1 NEW_LINE DEDENT return count NEW_LINE DEDENT def solve_queries ( arr , n ) : NEW_LINE INDENT global sum NEW_LINE arrr1 = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE typee = arrr1 [ 0 ] NEW_LINE if ( typee == 1 ) : NEW_LINE INDENT ql , qr , x = arrr1 [ 1 ] , arrr1 [ 2 ] , arrr1 [ 3 ] NEW_LINE temp = returnTwos ( x ) NEW_LINE temp1 = returnFives ( x ) NEW_LINE i = ql - 1 NEW_LINE while ( i < qr ) : NEW_LINE INDENT arr [ i ] = arr [ i ] * x NEW_LINE twos [ i ] += temp NEW_LINE fives [ i ] += temp1 NEW_LINE i += 1 NEW_LINE DEDENT DEDENT if ( typee == 2 ) : NEW_LINE INDENT ql , qr , y = arrr1 [ 1 ] , arrr1 [ 2 ] , arrr1 [ 3 ] NEW_LINE temp = returnTwos ( y ) NEW_LINE temp1 = returnFives ( y ) NEW_LINE i = ql - 1 NEW_LINE while ( i < qr ) : NEW_LINE INDENT arr [ i ] = ( i - ql + 2 ) * y NEW_LINE twos [ i ] = returnTwos ( i - ql + 2 ) + temp NEW_LINE fives [ i ] = returnFives ( i - ql + 2 ) + temp1 NEW_LINE i += 1 NEW_LINE DEDENT DEDENT if ( typee == 3 ) : NEW_LINE INDENT ql , qr = arrr1 [ 1 ] , arrr1 [ 2 ] NEW_LINE sumtwos = 0 NEW_LINE sumfives = 0 NEW_LINE i = ql - 1 NEW_LINE while ( i < qr ) : NEW_LINE INDENT sumtwos += twos [ i ] NEW_LINE sumfives += fives [ i ] NEW_LINE i += 1 NEW_LINE DEDENT sum += min ( sumtwos , sumfives ) NEW_LINE DEDENT DEDENT n , m = map ( int , input ( ) . split ( ) ) NEW_LINE arr = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT twos [ i ] = returnTwos ( arr [ i ] ) NEW_LINE fives [ i ] = returnFives ( arr [ i ] ) NEW_LINE DEDENT while ( m ) : NEW_LINE INDENT m -= 1 NEW_LINE solve_queries ( arr , n ) NEW_LINE DEDENT print ( sum ) NEW_LINE