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

最新文章

  1. SQL Server 2012附加数据库时,错误提示如下:尝试打开或创建物理时,CREATE FILE 遇到操作系统错误 5(拒绝访问。)
  2. SQL注入原理
  3. 纸上谈兵:排序算法简介及C实现
  4. nginx 反向代理 和lvs负载均衡
  5. python 前向引用
  6. [ALGO-3] K好数
  7. 玩转Android之Drawable的使用
  8. Early 80386 CPUs
  9. 如何取消一个本地svn目录与svn的联系(即恢复原有图标等)
  10. plugman创建cordova插件
  11. 构建微服务-使用OAuth 2.0保护API接口
  12. root用户不能修改iptable文件
  13. 项目笔记-vue
  14. 一般程序中的session
  15. c博客作业01--顺序、分支结构
  16. Mac OS mysql数据库安装与初始化
  17. MacBook上使用ssh localhost被拒绝
  18. JavaScript “跑马灯”抽奖活动代码解析与优化(二)
  19. maven项目没有src/test/java和src/test/resources目录问题解决
  20. 不同AI学科之间的联系

热门文章

  1. linux内核网络接收数据流程图【转】
  2. smb windows中使用的文件共享协议(主要用于与windows互通)
  3. 64_c2
  4. C# 数组 随机 排序
  5. Scrapy爬虫:抓取大量斗图网站最新表情图片
  6. swiper 滑动插件,小屏单个显示滑动,大屏全部显示
  7. hdu 1243(LCS变形)
  8. ubuntu上安装mysql及导入导出
  9. qTip2 Events详细说明
  10. python的ipython manage.py shell 引发的 No module named _argparse