Ural 1023. Buttons
2013-07-28 11:36
225 查看
1023. Buttons
Time limit: 2.0 secondMemory limit: 64 MB
Background
As you surely already know, Yekaterinburg has gotten its right to hold The Summer Olympic Games of the 2032. It is planned that it will be allowed to Russia as a country-organizer to emend a programof the games a bit. So, in order to improve the command result it has been decided to replace the competition in gymnastics by the competition in the new game "Buttons".
The rules of the game are very simple. There’s a small heap of K buttons before two players. The players in turns take buttons from the heap, moreover, at a time one can take a number of buttons from
1 up to L. The one who takes the last button is the winner.
The rules of the Olympic Games will be a bit harder then usual. The one, who is to make a first step according to a lot, has an opportunity to fix a number K with the following restriction
to it: 3 ≤K ≤ 108 (that is the exact number of buttons that has been prepared for the Olympic tournament). The player who is to make the second step fixes a number L that
satisfies the following conditions2 ≤ L < K.
Problem
A very crucial task is given to your team: you are to write a program that should help the second player to make his choice. In other words, given a number K your program is to find a number L thatguaranties a victory to the second player with a proper game of both sides.
So, for instance, there are only three buttons in the heap, the choice L = 2 provides for the victory of the second player. Really, if the first player takes only one button at his turn, the
second one wins, taking the two last buttons. On the contrary, if the first one takes two buttons, the second one wins, taking the last button.
Input
The standard input consists of one line, which contains an only integer number K — a number of buttons in the heap, that has fixed the first player at his turn.Output
To the standard output you are to write the only number L — the maximal number of buttons that can be taken at a time which provides for the victory of the second player. If there are severalthose numbers L, you should write the least. If there are no such numbers, you are to write 0 to the standard output.
Sample
input | output |
---|---|
3 | 2 |
Problem Source: Ural State University Internal Contest October'2000 Junior Session
/** * * 第一个人第一次取走k%(l+1)后,剩下的button是(l+1)的倍数,这时无论第二个人取几个(设他取i个),第一个下一次都可以取(l+1-i)个,使剩下的button也是(l+1)的倍数。 * */ #include <iostream> using namespace std; int main() { int l=3,k; cin>>k; while(k%l!=0) l++; cout<<l-1<<endl; return 0; }
相关文章推荐
- URAL 1023 Buttons(巴什博弈水题)
- ural 1023 Buttons
- POJ 2368|URAL 1023|Buttons|博弈论
- Ural 1023. Buttons
- URAL 1023 Buttons
- E - Buttons URAL - 1023
- URAL 1023 Buttons
- URAL 1023 Buttons 博弈
- URAL 1023 Buttons 博弈
- URAL 1023 Background 分析
- URAL1023
- 1023. Buttons
- 递推DP URAL 1244 Gentlemen
- Ural 1001. Reverse Root
- HDU 1023 (卡特兰数)
- URAL 1001 Reverse Root
- 数位类统计问题ural 1057
- URAL 1902. Neo-Venice
- Ural 1309 Dispute (递归)
- URAL 1996 Cipher Message 3 FFT + KMP