Find the player to reach at least N by multiplying with any value from given range | C ++ program for the above approach ; Function to find the winner ; Backtrack from N to 1 ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; char Winner ( int N ) { bool player = true ; while ( N > 1 ) { int den = ( player ) ? 9 : 2 ; int X = N / den , Y = N % den ; N = ( Y ) ? X + 1 : X ; player = ! player ; } if ( player ) return ' B ' ; else return ' A ' ; } int main ( ) { int N = 10 ; cout << Winner ( N ) ; return 0 ; }