POJ-2368-Buttons [找规律]
来源:互联网 发布:信用卡和淘宝有合作 编辑:程序博客网 时间:2024/06/05 08:26
题目链接:http://poj.org/problem?id=2368
Buttons
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<=L<K)使后取者能赢得比赛。若有多个则输出最小的。
如果k%(L+1)==0,则后取者赢,则只要找到K的因子中(大于2)的最小因子,让它减一即为L。 注意4!!!
#include<iostream>#include<cmath>using namespace std;int main(){long long int n,i;while(cin>>n){long long int ans=n;for(i=1;i<=sqrt(n);i++){if(n%i==0){if(i>2)ans=min(ans,i);//要求大于2if(n/i>2)//如果是4这类的情况ans=min(ans,n/i);} }if(ans>2)cout<<ans-1<<endl;elsecout<<"0"<<endl;}return 0; }
阅读全文
0 0
- POJ-2368-Buttons [找规律]
- poj 2800 找规律
- Codeforces Round #164(Div. 2) B. Buttons【找规律】
- Buttons(poj 2368)
- poj 2368 Buttons
- poj 2368 Buttons
- POJ 1068(找规律)
- 博弈 找规律 poj 2484
- POJ 1019 数学找规律
- poj 1063 找规律题目
- POJ 1218 囚犯问题 数学题找规律
- POJ 1095 找规律+递归打印
- POJ 2484 A Funny Game(找规律)
- Poj 2800 Joseph's Problem - 找规律
- POJ 1747 Expression(找规律 递归)
- poj 3090 (欧拉函数,找规律)
- poj 1426 数学推理找规律
- 【POJ】1663 - Number Steps(找规律)
- 建造者模式Builder
- Androd四大组件之Service服务
- jar包和war包的介绍和区别
- C++中struct和class的区别
- (人脸识别2-4)——关于CNN卷积神经网络
- POJ-2368-Buttons [找规律]
- Android源码研究环境搭建[6]调试系统源代码
- IO流(RandomAccessFile随机访问流)
- linux安装火狐浏览器
- javascript时间比较
- RAML文件的Java解析器raml-java-parser概述
- 2015-2016 ACM-ICPC Southwestern Europe Regional Contest (SWERC 15)训练总结【7/10】
- 美团js面试题
- 三种左边定宽,右边自适应布局方式