巴什博弈题!!!直接秒!!!
博弈详情参考:ACM 数论篇——博弈论
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* 题意:中文题,不解析!!!
*
* 分析:巴什博弈
*
* 解决:一共分为以下两种情况:
* i、当 sumStone = (oneMaxNum+1) * k (k 为任意整数)时,后手胜;
* ii、当 sumStone = (oneMaxNum+1) * k + s (k 为任意整数,s <= oneMaxNum)时,先手胜。
*
* 注意:有坑比的输入,一定不要用while(in.hasNext()){}
*
* @author TinyDolphin
*/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int caseNum;
int sumStone; // 一堆石头的总数量
int oneMaxNum; // 一次最多可以取走石头的数量
// 注意,此处有坑比的输入,一定不要有最外的循环。
// while (in.hasNext()) {
caseNum = in.nextInt();
while (caseNum-- != 0) {
sumStone = in.nextInt();
oneMaxNum = in.nextInt();
out.println(sumStone % (oneMaxNum + 1) == 0 ? "second" : "first");
}
// }
out.flush();
}
}