POJ2368(巴什博奕变形)
来源:互联网 发布:拼多多客服软件 编辑:程序博客网 时间:2024/06/01 08:04
Buttons
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 3073 Accepted: 781
Description
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 program of 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 <= 100 000 000 (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 conditions 2 <= L < K.
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 that guaranties 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.
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 <= 100 000 000 (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 conditions 2 <= L < K.
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 that guaranties 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 several those numbers L, you should write the least. If there are no such numbers, you are to write 0 to the standard output.
Sample Input
3
Sample Output
2
题目的规则跟巴什博奕是一致的,但是问得不是谁胜谁负,给定K,求怎么尽可能小的设定L使得第二个人必胜。
注意到L>=2,我们从1开始找到其所有因子,找到最小的大于2的因子i,输出i-1即可,因为此时(m%(i-1 + 1 )==0)
注意找因子时候要用O(logN)算法
/***********************************************************> OS : Linux 3.13.0-24-generic (Mint-17)> Author : yaolong> Mail : dengyaolong@yeah.net> Time : 2014年10月25日 星期六 11时13分18秒 **********************************************************/#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <cmath>using namespace std;int main(){ int n; cin >> n; int mmin = n; for ( int i = 1; i * i <= n; i++ ) { if ( n % i == 0 ) { if ( i > 2 ) { mmin = min ( mmin, i ); } if ( n / i > 2 ) { mmin = min ( mmin, n / i ); } } } if ( mmin > 2 ) { cout << mmin - 1 << endl; } else { cout << 0 << endl; } return 0;}
0 0
- poj2368 Buttons----巴什博奕变形
- POJ2368(巴什博奕变形)
- poj2368 Buttons
- POJ2368 Buttons
- POJ2368 巴什博弈
- hdu 2897 巴什博奕变形
- poj 2368 巴什博奕变形
- HDU2897( 巴什博奕变形)
- 变形
- 变形
- 变形
- 变形
- 变形
- HDU 2897 邂逅明下 巴什博奕变形
- hdu2897——邂逅明下(巴什博奕变形)
- 形容词变形
- 变形课
- 变形算法
- [ffmpeg 扩展第三方库编译系列] 关于 mingw32 下编译libcaca
- App项目设计开发完整流程
- 色彩格式之RGB与YUV
- nice命令
- leetcode - Sudoku Solver
- POJ2368(巴什博奕变形)
- 金现代工作,常用到的sql语句
- 自动轮播,类似字幕或图片自动滚动播放
- HDU steps 1.3.4 shǎ崽 OrOrOrOrz (int数组快排实现)
- POJ-1986-Distance Queries 解题报告
- 第9周 项目5 程序填充题(2)
- 水题——codeforces#275div2B
- linux C++学习之路
- 关于调用子函数给主函数指针分配内存