Codeforces Beta Round #90 A题
来源:互联网 发布:英语四级听力技巧知乎 编辑:程序博客网 时间:2024/06/01 07:54
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.
这里很清楚的解释了我们要干嘛!先写一个gcd函数,然后循环下去,一直遇到Antisimon should take gcd(5, 0) = 5 stones from the heap. As 0 < 5,
it is impossible and Antisimon loses.
就知道结果了,代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int gcd(int a,int b)
{
int temp,c,d;
while(b)
{
d=a%b;
a=b;
b=d;
}
return a;
}
int main()
{
int n,m,p,sum;
scanf("%d%d%d",&n,&m,&p);
while(1)
{
sum=gcd(n,p);
if(sum>p){printf("1\n") ;break;}
p-=sum;
sum=gcd(m,p);
if(sum>p){printf("0\n");break;}
p-=sum;
}
return 0;
}
- Codeforces Beta Round #90 A题
- Codeforces Beta Round #47 A题
- Codeforces Beta Round #1 A题
- Codeforces Beta Round #90 C题
- Codeforces Beta Round #75 (Div. 1 Only) A题
- Codeforces Beta Round #34 (Div. 2) A题解题报告
- Codeforces Beta Round #85 (Div. 2 Only) A题
- Codeforces Beta Round #65 (Div. 2) A题
- Codeforces Beta Round #89 (Div. 2) A题
- Codeforces Beta Round #87 (Div. 2 Only) A题
- Codeforces Beta Round #95 (Div. 2) A题
- Codeforces Beta Round #96 (Div. 2) A题
- Codeforces Beta Round #77 (Div. 2 Only) A题
- Codeforces Beta Round #84 (Div. 2 Only) A题
- Codeforces Beta Round #57 (Div. 2) A题
- Codeforces Beta Round #91 (Div. 2 Only) A题
- Codeforces Beta Round #92 (Div. 2 Only) A题
- Codeforces Beta Round #40 (Div. 2) A题
- phpcms调用同级栏目下的方法(单页和列表页和内容页各自不同)
- 关于类成员函数中访问同类对象的私有成员
- persistence.js 入门
- csc环境变量配置及csc命令详解
- 从零开始学C++之从C到C++(二):引用、数组引用与指针引用、内联函数inline、四种类型转换运算符
- Codeforces Beta Round #90 A题
- qt QSettings 用法总结
- 讲解如何在C/C++中调用Java的方法
- java内部类
- InnoDB存储引擎关键特性
- VMware9虚拟机和Fedora12安装-实现Windows和Linux文件共享
- 【Windows 7系统映像备份还原功能】
- C# 取电信公网IP并发送邮件
- 同步异步,阻塞非阻塞