NYOJ1032 【Save Princess】

描述
Yesterday, the princess was kidnapped by a devil. The prince has to rescue our pretty princess.

"OK, if you want to save the beautiful princess, you must answer my questions correctly."the devil says.

"No problem!".

"I’ll ask you t questions. For each question, I’ll tell you an integer n, you must tell me the i th beatuiful number. If your answer is wrong, the princess and you will all die".

"But what is the characteristic of the beautiful number?" Pince asks.

"Beautiful numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 
1, 2, 3, 4, 5, 6, 8, 9, 10, ...   shows the first 9 beautiful numbers.  
By convention, 1 is included. "

Can you help the prince to save the princess?
输入
The input for each case is an integer n(1≤n≤5000) and it is terminated by a negative integer.
输出
For each test case, you should print an integer which represents the i th beautiful number.
样例输入
2
3
-1
样例输出
2
3




#include<iostream>
#include<set>
using namespace std;
#define MAX 5010

int main()
{
    set<long long>a;
    a.insert(1);
    long long num[MAX];
    int index=0,data[]= {2,3,5};

    while(index<MAX)   
    {
        num[index]=*a.begin();
        a.erase(num[index]);
        for(int i=0; i<3; ++i)
            a.insert(num[index]*data[i]);
        ++index;
    }
    a.clear();
    int k;
    cin>>k;
    while(k>0)
    {
        cout<<num[k-1]<<endl;
        cin>>k;
    }
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值