Find the element in the matrix generated by given rules | Function to return the element in the rth row and cth column from the required matrix ; Condition for lower half of matrix ; Condition if element is in first row ; Starting element of AP in row r ; Common difference of AP in row r ; Position of element to find in AP in row r ; Driver Code
def getElement ( N , r , c ) : NEW_LINE INDENT if ( r > c ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT if ( r == 1 ) : NEW_LINE INDENT return c ; NEW_LINE DEDENT a = ( r + 1 ) * pow ( 2 , r - 2 ) ; NEW_LINE d = pow ( 2 , r - 1 ) ; NEW_LINE c = c - r ; NEW_LINE element = a + d * c ; NEW_LINE return element ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 4 ; R = 3 ; C = 4 ; NEW_LINE print ( getElement ( N , R , C ) ) ; NEW_LINE DEDENT