text: Largest odd divisor Game to check which player wins | C # implementation to find the Largest Odd Divisior Game to check which player wins ; Function to find the Largest Odd Divisior Game to check which player wins ; Check if n == 1 then player 2 will win ; Check if n == 2 or n is odd ; While n is greater than k and divisible by 2 keep incrementing tha val ; Loop to find greatest odd divisor ; Check if n is a power of 2 ; Check if cnt is not one then player 1 wins ; Driver code
code: using System ; class GFG { public static void findWinner ( int n , int k ) { int cnt = 0 ; if ( n == 1 ) Console . Write ( " No " ) ; else if ( ( n & 1 ) != 0 n == 2 ) Console . Write ( " Yes " ) ; else { int tmp = n ; int val = 1 ; while ( tmp > k && tmp % 2 == 0 ) { tmp /= 2 ; val *= 2 ; } for ( int i = 3 ; i <= Math . Sqrt ( tmp ) ; i ++ ) { while ( tmp % i == 0 ) { cnt ++ ; tmp /= i ; } } if ( tmp > 1 ) cnt ++ ; if ( val == n ) Console . Write ( " No " ) ; else if ( n / tmp == 2 && cnt == 1 ) Console . Write ( " No " ) ; else Console . Write ( " Yes " ) ; } } public static void Main ( string [ ] args ) { int n = 1 , k = 1 ; findWinner ( n , k ) ; } }