Find the player to reach at least N by multiplying with any value from given range | Java program for the above approach ; Function to find the winner ; Backtrack from N to 1 ; Driver Code
import java . util . * ; class GFG { static char Winner ( int N ) { boolean player = true ; while ( N > 1 ) { int den = ( player ) ? 9 : 2 ; int X = N / den ; int Y = N % den ; N = ( Y > 0 ) ? X + 1 : X ; player = ! player ; } if ( player ) return ' B ' ; else return ' A ' ; } public static void main ( String [ ] args ) { int N = 10 ; System . out . print ( Winner ( N ) ) ; } }