Generate an array with product of all subarrays of length exceeding one divisible by K | Function to check if the required array can be generated or not ; To check if divisor exists ; To store divisiors of K ; Check if K is prime or not ; If array can be generated ; Print d1 and d2 alternatively ; No such array can be generated ; Driver Code ; Given N and K ; Function Call
def array_divisbleby_k ( N , K ) : NEW_LINE INDENT flag = False NEW_LINE d1 , d2 = 0 , 0 NEW_LINE for i in range ( 2 , int ( K ** ( 1 / 2 ) ) + 1 ) : NEW_LINE INDENT if ( K % i == 0 ) : NEW_LINE INDENT flag = True NEW_LINE d1 = i NEW_LINE d2 = K // i NEW_LINE break NEW_LINE DEDENT DEDENT if ( flag ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT if ( i % 2 == 1 ) : NEW_LINE INDENT print ( d2 , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( d1 , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 5 NEW_LINE K = 21 NEW_LINE array_divisbleby_k ( N , K ) NEW_LINE DEDENT