程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> codeforces Epic Game 題解

codeforces Epic Game 題解

編輯:C++入門知識

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

這樣的題目一般都可以找公式的,但是本題卻是找不到什麼好的公式了。

只有暴力去模擬玩這個游戲了。還好因為其數據不大,故此也許出題者也是沒有公式的。


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<




  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved