因为每次拿取的东西最多为m,所以如果当前情况n%(m+1)==0 ,那么无论先手拿几个东西,后手都能通过拿东西使本回合拿东西总数为m+1,所以必胜.如果n%(m+1)!=0,那么第一个拿东西的人可以通过取物使(n-a)%(m+1) == 0 ,从而取胜.
代码如下:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int main ( )
{
int t,n,m;
scanf ( "%d" , &t );
while ( t-- )
{
scanf ( "%d%d" , &n , &m );
if ( n%(m+1) ) puts ( "Grass" );
else puts ( "Rabbit" );
}
}