Find winner in game of N balls , in which a player can remove any balls in range [ A , B ] in a single move | C ++ program of the above approach ; Function to find the winner of the game ; Stores sum of A and B ; If N is of the form m * ( A + B ) + y ; Otherwise , ; Driver code ; Input ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; string NimGame ( int N , int A , int B ) { int sum = A + B ; if ( N % sum <= A - 1 ) return " Bob " ; else return " Alice " ; } int main ( ) { int N = 3 , A = 1 , B = 2 ; cout << NimGame ( N , A , B ) << endl ; return 0 ; }