Sum of greatest odd divisor of numbers in given range | Function to return sum of first n odd numbers ; Recursive function to return sum of greatest odd divisor of numbers in range [ 1 , n ] ; Odd n ; Even n ; Function to return sum of greatest odd divisor of numbers in range [ a , b ] ; Driver code
def square ( n ) : NEW_LINE INDENT return n * n ; NEW_LINE DEDENT def sum ( n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT if ( n % 2 == 1 ) : NEW_LINE INDENT return ( square ( int ( ( n + 1 ) / 2 ) ) + sum ( int ( n / 2 ) ) ) ; NEW_LINE DEDENT else : NEW_LINE INDENT return ( square ( int ( n / 2 ) ) + sum ( int ( n / 2 ) ) ) ; NEW_LINE DEDENT DEDENT def oddDivSum ( a , b ) : NEW_LINE INDENT return sum ( b ) - sum ( a - 1 ) ; NEW_LINE DEDENT a , b = 3 , 9 ; NEW_LINE print ( oddDivSum ( a , b ) ) ; NEW_LINE