Lucky Numbers

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.

样例输入

2030

样例输出

68

提示

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.


来源

辽宁省赛2014

#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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值