Sum of greatest odd divisor of numbers in given range | C # program to find 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
using System ; class gfg { public int square ( int n ) { return n * n ; } public int sum ( int n ) { if ( n == 0 ) return 0 ; if ( n % 2 == 1 ) { return square ( ( n + 1 ) / 2 ) + sum ( n / 2 ) ; } else { return square ( n / 2 ) + sum ( n / 2 ) ; } } public int oddDivSum ( int a , int b ) { return sum ( b ) - sum ( a - 1 ) ; } } class geek { public static int Main ( ) { gfg g = new gfg ( ) ; int a = 3 , b = 9 ; Console . WriteLine ( g . oddDivSum ( a , b ) ) ; return 0 ; } }