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, ...
随机推荐
- Python调用C库
Python调用C库 Python可以利用ctypes库很方便地调用C的库函数. C库例程: # file: a.c int sum(int a, int b){ int t = 0; int ...
- 高级特性(8)- JavaBean构件
8.1 为何使用Bean8.2 编写Bean的过程8.3 使用Bean构造应用程序 8.3.1 将Bean打包成JAR文件 8.3.2 在开发环境中组合Bean8.4 Bean属性与事件的命名模式8. ...
- dsdfdsfd
aibang.com/show/1816725179-1268699976/product/7069113.html aibang.com/show/1816725179-1268699976/pro ...
- Android Drawable 与 LayerList综合汇总
先看需求.要求这样的效果 上代码 <?xml version="1.0" encoding="utf-8"? > <layer-list xm ...
- Webfrom 生成流水号 组合查询 Repeater中单选与复选控件的使用 JS实战应用
Default.aspx 网页界面 <%@ Page Language="C#" AutoE ...
- 配置nexus仓库
Nexus有许多默认仓库:Central,Releases,Snapshots,和3rd Party 1.配置central仓库 Nexus内置了Maven中央代理仓库Central.选择仓库列表中的 ...
- jquery-easyui界面皮肤设计
发现easy-ui 没有皮肤切换功能 正好工作要用就做了个 分享给大家 暂时做了绿色.橘黄.灰黑.蓝色.红色这5种颜色,大家也可以参照的多做几套更漂亮一点的! demo.rar (932.1 KB)
- 不包含SDK头文件, 补全API定义
/// @file main.cpp /// @brief 不包含SDK头文件, 补全API定义 #ifdef __cplusplus extern "C" { #endif /* ...
- 1.1.2-学习Opencv与MFC混合编程之---画图工具 画直线 画圆 画矩形
源代码地址:http://download.csdn.net/detail/nuptboyzhb/3961685 画图工具 1. 画直线 Ø 增加‘直线’菜单项,建立类向导: Ø 对CXX ...
- 国际化之MessageFormat与占位符
如果一个字符串文本中包含了多个与国际化相关的数据,可以使用MessageFormat类对这些数据进行批量处理. 例如: 在2016年1月9日的时候,一场台风导致了500间房屋的摧毁和¥1000000元 ...