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的更多相关文章

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

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

  2. 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, ...

  3. 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 ...

  4. UVa 136 Ugly Numbers【优先队列】

    题意:给出丑数的定义,不能被除2,3,5以外的素数整除的的数称为丑数. 和杭电的那一题丑数一样--这里学的紫书上的用优先队列来做. 用已知的丑数去生成新的丑数,利用优先队列的能够每次取出当前最小的丑数 ...

  5. UVa 136 - Ugly Numbers

    题目大意:只有素因子2,3,5的数叫做丑数.输出第1500个丑数即可. 这个...好吧,直接输出就是了.自己写一个小程序先计算一下,这就是黑盒测试的好处啊,“我们的目标是解决问题,而不是为了写程序而写 ...

  6. 136 Ugly Numbers(priority_queue+逆向求解要求数)

    题目链接: https://cn.vjudge.net/problem/UVA-136 /*问题 输出第1500个丑数,丑数的定义是不能被2,3,5以外的其他素数整除的数 解题思路 直接硬暴力先试一下 ...

  7. 丑数(Ugly Numbers, UVa 136)

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

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

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

  9. Ugly Numbers UVA - 136(优先队列+vector)

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

随机推荐

  1. C#基础 大盘点

      类型转换   tryParse    字符和整形转换   转译符:  /' 单引号      /" 双引号      // 反斜杠        /0 空字符       /a 感叹号( ...

  2. sql: sql developer tunnel转接

    Use putty tunnel instead of login terminal server 有时候本地直接ping不通sql 的server, 但另一个server能连上,这时就可以把端口和i ...

  3. this小记

    this小记 太久没有研究底层的js相关,今晚差点被紫红爸爸上课了. 正题 var net=new Object(); //定义一个全局变量net net.AjaxRequest=function(u ...

  4. linux-0.11抠代码-bootsect

    //bootfun.s .global asm_message .global asm_memmove .global asm_readsector .global asm_checkLBA .cod ...

  5. DOM API

    documentObject.documentElement 返回文档的根节点 document.documentElement; //返回<HTML><HTML>

  6. MSSQL - SqlDataAdapter连接数据库提高性能用法

    SqlDataAdapter 与 SqlConnection 和 SqlCommand 一起使用,以便在连接到 SQL Server 数据库时提高性能. SqlDataAdapter 的这一实现自动打 ...

  7. Spring中的p标签(转)good

    Spring的p标签是基于XML Schema的配置方式,目的是为了简化配置方式. 在XML文件头部添加xmlns:p="http://www.springframework.org/sch ...

  8. N-Queens And N-Queens II [LeetCode] + Generate Parentheses[LeetCode] + 回溯法

    回溯法 百度百科:回溯法(探索与回溯法)是一种选优搜索法,按选优条件向前搜索,以达到目标.但当探索到某一步时,发现原先选择并不优或达不到目标,就退回一步又一次选择,这样的走不通就退回再走的技术为回溯法 ...

  9. Keepalived安装工具

    装keepalived前,要先检查主机上是否已经安装, ps -ef | grep keepalive 不检查的话.easy把前人装的东西覆盖掉,那么曾经弄的配置文件都没了比較麻烦. 下面都为root ...

  10. 在JDBC中使用PreparedStatement代替Statement,同时预防SQL注入

    本篇讲诉为何在JDBC操作数据库的过程中,要使用PreparedStatement对象来代替Statement对象. 在前面的JDBC学习中,对于Statement对象,我们已经知道是封装SQL语句并 ...