Codeforces Round #114 (Div. 1) C. Wizards and Numbers 博弈论

C. Wizards and Numbers

题目连接:

http://codeforces.com/problemset/problem/167/C

Description

In some country live wizards. They love playing with numbers.

The blackboard has two numbers written on it — a and b. The order of the numbers is not important. Let's consider a ≤ b for the sake of definiteness. The players can cast one of the two spells in turns:

Replace b with b - ak. Number k can be chosen by the player, considering the limitations that k > 0 and b - ak ≥ 0. Number k is chosen independently each time an active player casts a spell.
Replace b with b mod a.
If a > b, similar moves are possible.

If at least one of the numbers equals zero, a player can't make a move, because taking a remainder modulo zero is considered somewhat uncivilized, and it is far too boring to subtract a zero. The player who cannot make a move, loses.

To perform well in the magic totalizator, you need to learn to quickly determine which player wins, if both wizards play optimally: the one that moves first or the one that moves second.

Input

The first line contains a single integer t — the number of input data sets (1 ≤ t ≤ 104). Each of the next t lines contains two integers a, b (0 ≤ a, b ≤ 1018). The numbers are separated by a space.

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

Output

For any of the t input sets print "First" (without the quotes) if the player who moves first wins. Print "Second" (without the quotes) if the player who moves second wins. Print the answers to different data sets on different lines in the order in which they are given in the input.

Sample Input

4
10 21
31 10
0 1
10 30

Sample Output

First
Second
Second
First

Hint

题意

中文题面见:http://acm.uestc.edu.cn/#/problem/show/1169

题解:

651210-20160216183847032-1210243258.png

代码

#include<bits/stdc++.h>
using namespace std;

int check(long long a,long long b)
{
    if(a==0)return 0;
    if(check(b%a,a))
    {
        b/=a;
        return !((b%(a+1))&1);
    }
    return 1;
}
int main()
{
    int t;scanf("%d",&t);
    while(t--)
    {
        long long a,b;
        cin>>a>>b;
        if(a>b)swap(a,b);
        if(check(a,b))cout<<"First"<<endl;
        else cout<<"Second"<<endl;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值