课堂学习——Beautiful number

It is not ugly number
Time Limit:2000MS  Memory Limit:65535K


描述
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, ...shows the 
first 10 ugly numbers. By convention, 1 is included. Then, here are the first 10 Not ugly numbers:7, 11, 13, 14, 17, 19, 
21, 22, 23, 26. Given the integer n, write a program to find and print the n'th Not ugly number.
输入格式
First line is T(T<=10000), the number of cases.
The T lines following. Each line of the input contains a positive integer n (n <= 100000000).
输出格式
For each case, output the n'th Not ugly number .
输入样例
3
1
2
9
输出样例
7
11
23

#include <iostream>
#include <queue>
#include <vector>
#include <cstdio>
using namespace std;
typedef pair<unsigned long ,int> node_type;
int main()
{
    unsigned long result[1700];
    priority_queue<node_type,vector<node_type>,greater<node_type> >Q;
    Q.push(node_type(1,2));
    for(int i=0;i<1700;++i)
    {
        node_type node=Q.top();
        Q.pop();
        switch(node.second){
            case 2:
            Q.push(make_pair(node.first*2,2));
            case 3:
            Q.push(make_pair(node.first*3,3));
            case 5:
            Q.push(make_pair(node.first*5,5));
        }
        result[i]=node.first;
    }
    int T,n,i;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        for(i=0;i<1700;++i)
        {
            if(result[i]-i-1>=n)
            {
                printf("%d\n",n+i);
                break;
            }
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值