Lucky Numbers
时间限制: 1 Sec 内存限制: 128 MB提交: 22 解决: 9
[ 提交][ 状态][ 论坛]
题目描述
A lucky number is made by the following rules:
Given a positive integer sequence {x | 1 <= x <= n}. From the first number, delete the last one in every 2 numbers. Select the minimum that has not been unused from the rest numbers. This number is xi. Then delete the last number in every xi numbers.
输入
There are several test cases, ended by the end of file.
Each test case has a positive integer n.(3<=n<=10000)
输出
Output the number of lucky numbers in one line.
样例输入
样例输出
提示
eg.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
For the first time, delete the last number in every two numbers. The sequence become 1 3 5 7 9 11 13 15 17 19
For the second time, the minimum number that has never been used is 3. Delete the last number in every 3 numbers. The sequence become 1 3 7 9 13 15 19
For the third time, the minimum number that has never been used is 7. Delete the last number in every 7 numbers. The sequence becomes 1 3 7 9 13 15.
Then you cannot delete any numbers. There are 6 numbers left over. So the answer is 6.
来源
#include<iostream>
using namespace std;
int b[200];
void init(){
int a[10005];
for(int i=1;i<=10000;i++)
a[i]=1;
int s=0,sum=10000;
int t=2,st=1; b[0]=2;
while(sum>=t){
for(int i=1;i<=10000;i++){
if(a[i]>0){
s++;
if(s==t){
a[i]=0;
s=0;
}
}
}
s=0;
sum=0;
for(int i=1;i<=10000;i++)
if(a[i]==1)
sum++;
for(int i=t+1;i<=10000;i++)
if(a[i]==1){
t=i;
b[st++]=t;
break;
}
}
}
int main(){
init(); //把所有能取到的数保存在b[]里面
int n;
while(cin>>n){
int i=0;
while(n>=b[i]){
n=n-n/b[i];
i++;
}
cout<<n<<endl;
}
return 0;
}