NYOJ1032 【Save Princess】

来源:互联网 发布:星海牌萨克斯淘宝网 编辑:程序博客网 时间:2024/05/21 02:48
描述
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.
样例输入
23-1
样例输出
23




#include<iostream>#include<set>using namespace std;#define MAX 5010int 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;}




0 0
原创粉丝点击