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

题解:

代码

#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;
}
}

Codeforces Round #114 (Div. 1) C. Wizards and Numbers 博弈论的更多相关文章

  1. Codeforces Round #114 (Div. 1) B. Wizards and Huge Prize 概率dp

    B. Wizards and Huge Prize Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  2. Codeforces Round #114 (Div. 1) A. Wizards and Trolleybuses 物理题

    A. Wizards and Trolleybuses Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  3. Codeforces Round #114 (Div. 1) D. Wizards and Roads 笛卡尔树+树贪心+阅读题

    D. Wizards and Roads 题目连接: http://www.codeforces.com/contest/167/problem/D Description In some count ...

  4. Codeforces Round #114 (Div. 1) E. Wizards and Bets 高斯消元

    E. Wizards and Bets 题目连接: http://www.codeforces.com/contest/167/problem/E Description In some countr ...

  5. Codeforces Round #114 (Div. 2)

    Codeforces Round #114 (Div. 2) 代码 Codeforces Round #114 (Div. 2) C. Wizards and Trolleybuses 思路 每条车的 ...

  6. Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题

    A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...

  7. Codeforces Round #235 (Div. 2) D. Roman and Numbers(如压力dp)

    Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standard i ...

  8. Codeforces Round #235 (Div. 2) D. Roman and Numbers 状压dp+数位dp

    题目链接: http://codeforces.com/problemset/problem/401/D D. Roman and Numbers time limit per test4 secon ...

  9. Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题

    A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finish ...

随机推荐

  1. monkey测试===修改adb的默认端口

    最近电脑上由于公司系统的原因,adb的端口被占用了,但是占用端口的进程是必须启动的,不能被杀死,在网上找了很多办法,大家都是说杀死占用端口的进程.这个方法并不适用我,所以在此给大家一个新的方法.新建一 ...

  2. python 使用headless chrome滚动截图

    from selenium import webdriver from selenium.webdriver.chrome.options import Options import util chr ...

  3. Django 国内最全教程

    https://code.ziqiangxuetang.com/django/django-tutorial.html

  4. artdialog自定义多个按钮

    在实际运用到的过程中artdialog弹出框下面的按钮不止一个 可以自己定义多个按钮 function view_show(cust_id){$.dialog({        id: 'view_c ...

  5. 【python】配置文件

    来源:http://developer.51cto.com/art/201003/189885.htm python 读写配置文件在实际应用中具有十分强大的功能,在实际的操作中也有相当简捷的操作方案, ...

  6. Git----创建远程分支,并将文件上传到创建的远程分支上

    1.首先创建一个远程仓库 2.将远程仓库克隆到本地 (1)本地新建文件夹,命令行进入文件夹,执行clone操作 (2) git clone git@github.com:Lucky-Syw/lucky ...

  7. AC日记——双栈排序 洛谷 P1155

    双栈排序 思路: 二分图染+模拟: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1005 #define ...

  8. WebDriver自动化测试工具(1)---环境搭建

    Webdriver是一个前端自动化测试工具,可以模拟用户点击链接,填写表单,点击按钮等操作,下面介绍其使用 一.下载WebdriverC#类库以及对应浏览器驱动 http://www.selenium ...

  9. gulp-connect插件浏览器实时同步刷新

    1.在站点路径里打开cmd控制台. 输入:cnpm install gulp-connect --save-dev 2.编辑gulpfile.js 3.控制台执行gulp任务 输入gulp serve ...

  10. bzoj 1407 扩展欧几里德

    思路:枚举洞穴个数,用扩展欧几里德暴力判断没两个人的周期. #include<bits/stdc++.h> #define LL long long #define fi first #d ...