136 - Ugly Numbers
| Ugly Numbers |
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 and Output
There is noinput to this program. Output should consist of a single line asshown below, with <number> replaced by the number computed.
Sample output
The 1500'th ugly number is <number>.
#include<stdio.h>
int main(void)
{
int un[1505]={0};
int m2=0,m3=0,m5=0,i,t;
un[0]=1;
for(i=1;i<1500;i++)
{
if(2*un[m2]>3*un[m3])
t=un[m3]*3;
else
t=un[m2]*2;
if(t>un[m5]*5)
t=un[m5]*5; if(t == 2*un[m2]) m2++;
if(t == 3*un[m3]) m3++;
if(t == 5*un[m5]) m5++; un[i]=t;
}
printf("The 1500'th ugly number is %d.\n",un[1499]);
return 0;
}
136 - Ugly Numbers的更多相关文章
- UVA.136 Ugly Numbers (优先队列)
UVA.136 Ugly Numbers (优先队列) 题意分析 如果一个数字是2,3,5的倍数,那么他就叫做丑数,规定1也是丑数,现在求解第1500个丑数是多少. 既然某数字2,3,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, ...
- 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 ...
- UVa 136 Ugly Numbers【优先队列】
题意:给出丑数的定义,不能被除2,3,5以外的素数整除的的数称为丑数. 和杭电的那一题丑数一样--这里学的紫书上的用优先队列来做. 用已知的丑数去生成新的丑数,利用优先队列的能够每次取出当前最小的丑数 ...
- UVa 136 - Ugly Numbers
题目大意:只有素因子2,3,5的数叫做丑数.输出第1500个丑数即可. 这个...好吧,直接输出就是了.自己写一个小程序先计算一下,这就是黑盒测试的好处啊,“我们的目标是解决问题,而不是为了写程序而写 ...
- 136 Ugly Numbers(priority_queue+逆向求解要求数)
题目链接: https://cn.vjudge.net/problem/UVA-136 /*问题 输出第1500个丑数,丑数的定义是不能被2,3,5以外的其他素数整除的数 解题思路 直接硬暴力先试一下 ...
- 丑数(Ugly Numbers, UVa 136)
丑数(Ugly Numbers, UVa 136) 题目描述 我们把只包含因子2.3和5的数称作丑数(Ugly Number).求按从小到大的顺序的第1500个丑数.例如6.8都是丑数,但14不是,因 ...
- 【UVA - 136】Ugly Numbers(set)
Ugly Numbers Descriptions: Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequ ...
- Ugly Numbers UVA - 136(优先队列+vector)
Problem Description Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, ...
随机推荐
- js动态向页面中添加表格
我们在实际开发中经常会想要实现如下情况: 点击某个按钮,然后动态的网页面里面添加一个表格或者一行,这个更加灵活方便.但是实现起来肯定不能像在页面里面直接写标签来的容易,以下是我项目中的代码,拿过来分享 ...
- oracle 11g 11.2.0.1 设置HuagePage导致TRC 变大 变多
最近发现diag/..../trac/ 目录下 sid_ora_xxxx.trc 文件大小为11M 而且类似文件数量很大.导致占用了8G硬盘空间 另外个同事说他的DG没有这个问题. 都一样的系统和一 ...
- 最小生成树(MST)[简述][模板]
Prim(添点法) 1. 任选一点(一般选1), 作为切入点,设其与最小生成树的距离为0(实际上就是选一个点,将此树实体化),. 2. 在所有未选择的点中选出与最小生成树距离最短的, 累计其距离, 并 ...
- 超级坑人的Couchbase数据库问题!!!
官网:http://www.couchbase.com/ 版本:1.8版 问题描述: 某次服务器因意外断电重启后,就进入不了Couchbase控制台,显示 "无法显示该页" 的错误 ...
- opencv视频播放
在一个界面上显示一张图片.是一件非常easy的事情,但说到要显示视频.刚開始学习的人可能不知道怎么处理,事实上,一般来说能够理解为视频就是图片以人眼察觉不到的速度高速更新. 曾经用摄像头採集视频显示在 ...
- PHP - 判断php是否对表单数据内的特殊字符自动转义
get_magic_quotes_gpc 有两个返回值: 0:在php.ini文件中已经关闭自动转移. 1:在php.ini文件中已经开启自动转移. 由此函数进行判断表单是否转移: /** * * m ...
- Hystrix 使用与分析
转载请注明出处哈:http://hot66hot.iteye.com/admin/blogs/2155036 一:为什么需要Hystrix? 在大中型分布式系统中,通常系统很多依赖(HTTP,hess ...
- 基于visual Studio2013解决C语言竞赛题之1021九九乘法表
题目 解决代码及点评 /* 功能:请编程序按如下格式打印一个直角三角形的九九乘法表: 1 2 3 4 5 6 7 8 9 4 6 8 10 12 14 16 18 9 1 ...
- Git本地分支版本号过低导致的push错误 error: failed to push some refs to ... 及兴许amend
今天在用git的时候遇到了一个问题.在想远程分支push的时候,出现了以下的错误: ! [remote rejected] master -> refs/for/master (change 1 ...
- SDL2源码分析6:拷贝到渲染器(SDL_RenderCopy())
===================================================== SDL源码分析系列文章列表: SDL2源码分析1:初始化(SDL_Init()) SDL2源 ...