CodeForces 119A Epic Game
2016-02-10 19:50
267 查看
A. Epic Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number
a and Antisimon receives number
b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of
the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has
strictly less stones left than one needs to take).
Your task is to determine by the given a,
b and n who wins the game.
Input
The only string contains space-separated integers a,
b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of
stones in the pile.
Output
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Sample test(s)
Input
Output
Input
Output
Note
The greatest common divisor of two non-negative integers
a and b is such maximum positive integer
k, that a is divisible by
k without remainder and similarly,
b is divisible by k without remainder. Let
gcd(a, b) represent the operation of calculating the greatest common divisor of numbers
a and b. Specifically,
gcd(x, 0) = gcd(0, x) = x.
In the first sample the game will go like that:
Simon should take gcd(3, 9) = 3 stones from the heap. After his move the heap has
6 stones left.
Antisimon should take gcd(5, 6) = 1 stone from the heap. After his move the heap has
5 stones left.
Simon should take gcd(3, 5) = 1 stone from the heap. After his move the heap has
4 stones left.
Antisimon should take gcd(5, 4) = 1 stone from the heap. After his move the heap has
3 stones left.
Simon should take gcd(3, 3) = 3 stones from the heap. After his move the heap has
0 stones left.
Antisimon should take gcd(5, 0) = 5 stones from the heap. As
0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As
n is even, Antisimon takes the last stone and Simon can't make a move after that.
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number
a and Antisimon receives number
b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of
the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has
strictly less stones left than one needs to take).
Your task is to determine by the given a,
b and n who wins the game.
Input
The only string contains space-separated integers a,
b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of
stones in the pile.
Output
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Sample test(s)
Input
3 5 9
Output
0
Input
1 1 100
Output
1
Note
The greatest common divisor of two non-negative integers
a and b is such maximum positive integer
k, that a is divisible by
k without remainder and similarly,
b is divisible by k without remainder. Let
gcd(a, b) represent the operation of calculating the greatest common divisor of numbers
a and b. Specifically,
gcd(x, 0) = gcd(0, x) = x.
In the first sample the game will go like that:
Simon should take gcd(3, 9) = 3 stones from the heap. After his move the heap has
6 stones left.
Antisimon should take gcd(5, 6) = 1 stone from the heap. After his move the heap has
5 stones left.
Simon should take gcd(3, 5) = 1 stone from the heap. After his move the heap has
4 stones left.
Antisimon should take gcd(5, 4) = 1 stone from the heap. After his move the heap has
3 stones left.
Simon should take gcd(3, 3) = 3 stones from the heap. After his move the heap has
0 stones left.
Antisimon should take gcd(5, 0) = 5 stones from the heap. As
0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As
n is even, Antisimon takes the last stone and Simon can't make a move after that.
#include<stdio.h> int gcd(int a,int b){ return b==0?a:gcd(b,a%b); } int main(){ int a,b,n; while(scanf("%d %d %d",&a,&b,&n)!=EOF){ while(1){ n-=gcd(a,n); if(n<0){ printf("1\n"); break; } n-=gcd(b,n); if(n<0){ printf("0\n"); break; } } } return 0; }
相关文章推荐
- 书
- [笔记][Web]利用JS生成博文目录及CSS定制博客
- Java基础 数列排序
- ViewDragHelper 使用
- Dalvik和JVM的区别
- Chapter 1-02
- Chapter 1-01
- 利用DelayQueue实现延时消息队列(简易版MQ)
- PID控制器的数字实现及C语法讲解
- 类的编写
- const
- 蓝桥基础练习学习记录
- linux下安装php7+mysql5.7+nginx
- handler用法
- Rust学习笔记
- Atitit.nosql api 标准化 以及nosql数据库的实现模型分类差异
- Atitit.nosql api 标准化 以及nosql数据库的实现模型分类差异
- Atitit.nosql api 标准化 以及nosql数据库的实现模型分类差异
- Android 解析 xml
- day15-----------集合框架(传智视频)