codeforces Epic Game 题解

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 nstones.
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 ab and n who
wins the game.

Input

The only string contains space-separated integers ab 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

这样的题目一般都可以找公式的,但是本题却是找不到什么好的公式了。

只有暴力去模拟玩这个游戏了。还好因为其数据不大,故此也许出题者也是没有公式的。

namespace{

	int GCD(int a, int b)
	{
		if (1 == a || b == 1) return 1;
		while (b)
		{
			int t = b;
			b = a%b;
			a = t;
		}
		return a;
	}
}

void EpicGame()
{
	int a, b, c, d;
	cin>>a>>b>>c;
	bool goGame = 0;
	while (c >= 0)
	{
		if (goGame) d = GCD(b, c);
		else d = GCD(a, c);
		c -= d;
		goGame = !goGame;
	}
	cout<<goGame;
}

codeforces Epic Game 题解,码迷,mamicode.com

时间: 2024-10-12 20:47:47

codeforces Epic Game 题解的相关文章

codeforces Flipping Game 题解

Iahub got bored, so he invented a game to be played on paper. He writes n integers a1,?a2,?...,?an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1?≤?i?≤?j?≤?n) and flips all values 

codeforces The Wall - 题解

Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme o

codeforces Gravity Flip 题解

Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are n columns of toy cubes in the box arranged in a line. The i-th

codeforces A. TL 题解

Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote m 

Codeforces Unlucky Ticket 题解

Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket is lucky. Let us remind you th

codeforces A. k-String 题解

A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string

codeforces A. Array题解

Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the first set is less than zero (?<?0). The product of all numbers in the secon

codeforces A. Cakeminator 题解

本题思路: 1 先扫描行,如果可以吃,就数吃了多少格,然后做好标志 2 扫描列,同样处理 扫描完就可以出答案了. 时间效率是O(n*m)了.算是暴力法 题目: http://codeforces.com/problemset/problem/330/A #include <vector> #include <algorithm> #include <utility> #include <string> #include <queue> #incl

Codeforces Amusing Joke 题解

So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name i