poj2368 Buttons----巴什博奕变形
来源:互联网 发布:淘宝尺寸表怎么做 编辑:程序博客网 时间:2024/05/19 18:15
Buttons
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2458 Accepted: 609
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
Source
Ural State University Internal Contest October'2000 Junior Session
给你一个k,求出最小的L使得k%(1+L)=0
所以求出k的最小因子减去1就行了
#include<iostream>#include<cstdlib>#include<stdio.h>#include<algorithm>using namespace std;int a[1010];int main(){ int n; while(scanf("%d",&n)!=EOF) { bool flag=false; int l=0; for(int i=1;i*i<=n;i++) { if(n%i==0) { a[l++]=i; a[l++]=n/i; } } sort(a,a+l); /*for(int i=0;i<l;i++) cout<<a[i]<<" "; cout<<endl;*/ for(int i=0;i<l;i++) { if(a[i]>2) { cout<<(a[i]-1)<<endl; flag=true; break; } } if(!flag) puts("0"); }}
- poj2368 Buttons----巴什博奕变形
- POJ2368(巴什博奕变形)
- poj2368 Buttons
- POJ2368 Buttons
- 【巴什博奕】poj 2369 Buttons
- POJ 2368(Buttons) 巴什博弈变形 Java
- Buttons
- POJ2368 巴什博弈
- hdu 2897 巴什博奕变形
- poj 2368 巴什博奕变形
- HDU2897( 巴什博奕变形)
- ExtJS buttons
- B. Buttons
- Two Buttons
- Two Buttons
- Two Buttons
- Android-Buttons
- Radio Buttons
- Eclipse快捷键大全(转载)
- 网络编程学习
- 第二周JAVA上机实验(二)判断这个数是几位数、是否是回文数
- C++与C#对比学习:内存管理
- spring+quartz定时任务
- poj2368 Buttons----巴什博奕变形
- java中equals和==的区别
- 表达式和运算符
- 算法导论 6-3 Young氏矩阵
- c# 正在终止线程 关闭UdpClient
- C++嵌套调用函数
- PHP页面跳转几种实现方法
- 如何更好的使用google
- session error session错误的解决办法