A. Epic Game
来源:互联网 发布:俄亥俄州知乎 编辑:程序博客网 时间:2024/04/29 05:25
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.
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.
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
3 5 9
0
1 1 100
1
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:
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 <iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;void swap(int & a, int & b) { int c = a; a = b; b = c; } int gcd(int a,int b) { if(0 == a ) { return b; } if( 0 == b) { return a; } if(a > b) { swap(a,b); } int c; for(c = a % b ; c > 0 ; c = a % b) { a = b; b = c; } return b; }int main(){int a,b,n;int flag;scanf("%d %d %d",&a,&b,&n);while(1){n-=gcd(a,n);if(n==0){flag=1;printf("0\n");break;}n-=gcd(b,n);if(n==0){flag=2;printf("1\n");break;}}return 0;}
- A. Epic Game
- 119A - Epic Game
- CodeForces 119A Epic Game
- CF 119A Epic Game
- codeforces 119A Epic Game(模拟水题)
- codeforces——119A——Epic Game
- codeforces Epic Game 题解
- ZCMU-1431-Epic Game
- Codeforces Epic Game
- Epic Fail of a Genie
- A Game
- A Game
- A. Game
- A. Game
- Gym 100685E Epic Fail of a Genie(贪心)
- Epic 面试
- SAP EPIC
- EPIC flow
- 为什么程序员总被认为是吊丝群体?
- unity3d 游戏内付费
- python MySQLdb在windows环境下的快速安装、问题解决方式
- rman 命令简析
- 求职面试、指点迷津各类经验汇总
- A. Epic Game
- Lucene的分页查询
- 排序之二:希尔排序
- javascript之在iframe中关闭parent窗口
- CListCtrl控件使用方法总结(二)
- VS TFS源码分析软件PATFS的安装Endpoint方法
- Mysql数据类型
- [MFC]选择目录对话框和选择文件对话框
- 开源 免费 java CMS - FreeCMS1.2-功能说明-系统配置