一个石头游戏
两人玩一游戏,在他们面前有一堆石头,数量为n,双方轮流取石头,条件是取的石头的数目是非负的整数且是2的幂(例如1,2,4,8等),拿到最后一个石头的人获胜,假设双方都是尽力想要取胜的。编一道程序来解决问题,,使得输入石头的总数后,输出哪方获胜且第一次拿的石头数。
上面是我翻译的,下面是原题。
Two Nikifors play a funny game. There is a heap of N stones in front of them. Both Nikifors in turns take some stones from the heap. One may take any number of stones with the only condition that this number is a nonnegative integer power of 2 (e.g. 1, 2, 4, 8 etc.). Nikifor who takes the last stone wins. You are to write a program that determines winner assuming each Nikifor does its best.
Input
An input contains the only positive integer number N (condition N ≤ 10250 holds).
Output
The first line of an output file should contain 1 in the case the first Nikifor wins and 2 in case the second one does. If the first Nikifor wins the second line should contain the minimal number of stones he should take at the first move in order to guarantee his victory.
Sample
input
8
output
1
2
有谁能分析一下题目?十分感谢。
[[it] 本帖最后由 xujie3 于 2008-8-21 14:26 编辑 [/it]]