题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1846

只有一堆石子共n个。每次从最少取1个,最多取m个,最后取光的人取胜。问先手是否有必胜策略,第一步该怎么取。

如果n=(m+1)*k+s (s!=0) 那么先手一定必胜,因为第一次取走s个,接下来无论对手怎么取,我们都能保证取到所有(m+1)倍数的点,那么循环下去一定能取到最后一个。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>

using namespace std;

int n,m;

int main()
{
    int t;
    cin>>t;
    while( t-- )
    {
        cin>>n>>m;
        if( n%(m+1) ) puts("first");
        else puts("second");
    } 
}