/* A C++ program to find Grundy Number for
a game which is one-pile version of Nim.
Game Description : The game starts with a pile of
n stones, and the player to move may take any
positive number of stones upto k only.
The last player to move wins. */
using namespace std;
// A function to Compute Grundy Number of 'n'
// Only this function varies according to the game
int calculateGrundy (int n,int k)
if (n == 0)
if (n == 1)
if (n == 2)
if (n == 3)
// Driver program to test above functions
int n = 47;
int k=3; // you can change the value of k accordingly as you are allowed to pick upto k stones
printf ("%d", calculateGrundy (n,k));