Problem Description

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, 15, ...shows the first 11 ugly numbers.

By convention, 1 is included.

Write a program to find and print the 1500’th ugly number

Input

There is no input to this program.

Output

Output should consist of a single line as shown below, with '<number>' replaced by the number computed.

SampleOutput

The 1500'th ugly number is <number>.

题目大意:

丑数是指不能被2,3,5以外的其他素数整除的数。把丑数从小到大排列起来

结果如下:

1,2,3,4,5,6,8,9,10,12,15,…

求第1500个丑数

思路:

一般暴力求解那肯定会T,所以我们可以借助优先队列将其进行优化,注意的是需要用long long 型,这大家应该也都知道多嘴了ヾ(=゚・゚=)ノ喵♪。

具体看代码:

#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
#define ll long long
const int maxx=;
int main()
{
ll a,b,c;
//优先队列
priority_queue<ll,vector<ll>,greater<ll> >q;
q.push();//初始化为 1;
int num=;//计数;
ll ans;
while(num<maxx)
{
ans=q.top();
q.pop();
num++;
if(num==)
{
printf("The 1500'th ugly number is %d.\n", ans);
break;
}
//如果ans 为ugly ,则2*ans,3*ans,5*ans都是丑数;
a=ans*;
b=ans*;
c=ans*;
// a 如果与 b或c是同一数的因数关系,那么该数一定在b或c中出现过
// 因为b或c比a大
if((a%)&&(a%))
{
q.push(a);
}
if((b%))
{
q.push(b);
}
q.push(c);
}
return ;
}

还有一种操作就是下面这种o(゚Д゚)っ啥!,前提是已经知道结果:

#include<iostream>
using namespace std;
int main()
{
cout<<"The 1500'th ugly number is 859963392.\n";
}

Ugly Numbers UVA - 136(优先队列+vector)的更多相关文章

  1. 丑数(Ugly Numbers, UVa 136)

    丑数(Ugly Numbers, UVa 136) 题目描述 我们把只包含因子2.3和5的数称作丑数(Ugly Number).求按从小到大的顺序的第1500个丑数.例如6.8都是丑数,但14不是,因 ...

  2. Ugly Numbers UVA - 136

    Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9 ...

  3. UVA.136 Ugly Numbers (优先队列)

    UVA.136 Ugly Numbers (优先队列) 题意分析 如果一个数字是2,3,5的倍数,那么他就叫做丑数,规定1也是丑数,现在求解第1500个丑数是多少. 既然某数字2,3,5倍均是丑数,且 ...

  4. UVA - 136 Ugly Numbers(丑数,STL优先队列+set)

    Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9 ...

  5. UVA - 136 Ugly Numbers (有关set使用的一道题)

    Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, ...

  6. 【UVA - 136】Ugly Numbers(set)

    Ugly Numbers Descriptions: Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequ ...

  7. UVa136 Ugly Numbers(优先队列priority_queue)

    Ugly Numbers 题目 Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, ...

  8. 136 - Ugly Numbers

     Ugly Numbers  Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3 ...

  9. Ugly Numbers(STL应用)

    题目链接:http://poj.org/problem?id=1338 Ugly Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Sub ...

随机推荐

  1. Jquery 2.0+版本不支持IE8,如何解决?

    用了JQuery2.0+以后,在IE8下会报错,下面是我的方法. 先看代码: <!--[if !IE]> -->        <script src="/Scrip ...

  2. css background之设置图片为背景技巧

    原文 Background是什么意思,翻译过来有背景意思.同样在css里面作为css属性一成员同样是有背景意思,并且是设置背景图片.背景颜色.背景图片截取等样式. 首先先来看看background有那 ...

  3. 【软件工程】Alpha冲刺 (6/6)

    链接部分 队名:女生都队 组长博客: 博客链接 作业博客:博客链接 小组内容 恩泽(组长) 过去两天完成了哪些任务 描述 tomcat的学习与实现 服务器后端部署,API接口的beta版实现 后端代码 ...

  4. ReSharper “Cannot resolve symbol” even when project builds

    ReSharper “Cannot resolve symbol” even when project builds   This worked for me (VS2012u4, R# 7.1.3) ...

  5. 在vue项目中使用element-ui的Upload上传组件

    <el-upload v-else class='ensure ensureButt' :action="importFileUrl" :data="upLoadD ...

  6. flutter webview_flutter 设置cookies

    WebViewController _controller; onWebViewCreated: (WebViewController wvc) { _controller = wvc; } onPa ...

  7. hadoop安装和环境配置---1

    一.安装java 1.下载 : yum install java-1.7.0-openjdk 2.配置环境变量 vim /etc/profile 要先看自己安装的java全名 然后再环境配置 expo ...

  8. 初识消息中间件之 ==> ActiveMQ

    一.消息队列概述 消息(Message)是指在应用间传送的数据.消息可以非常简单,比如只包含文本字符串,也可以更复杂,可能包含嵌入对象. 消息队列(Message Queue)是一种应用间的通信方式, ...

  9. 语音文件 pcm 静默(静音)判断

    转载:http://www.voidcn.com/relative/p-fwdkigvh-bro.html pcm 文件存储的是 原始的声音波型二进制流,没有文件头. (1)首先要确认 pcm文件的每 ...

  10. Linux命令集锦:ansible命令

    ansible 命令主要用于批量管理,来实现自动化管理.常用批量操作包括:主机分组管理.实时批量执行命令或脚本.实时批量分发文件或目录.定时同步文件等. 一.安装 ansible yum instal ...