题目:

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 ‘’ replaced by the number computed. Sample Output The 1500'th ugly number is .

AC代码:

#include <iostream>
using namespace std;
int min1 (int a,int b)
{return a<b?a:b;}//自定义函数
int main()
{
long long a[1500];
a[0] = 1;
long long a2=0,a3=0,a5=0;
for(int i=1;i<1500;i++)
{
while(a[a2]*2<=a[i-1]) a2++;
while(a[a3]*3<=a[i-1]) a3++;
while(a[a5]*5<=a[i-1]) a5++;
a[i]= min1(min1(a[a2]*2,a[a3]*3),a[a5]*5);
}
cout<<"The 1500'th ugly number is "<<a[1499]<<'.'<<endl;
}

做此类数学题一定要冷静啊!

不要首先想着捷径,一定要先想正轨,更容易解出来

因子问题 I - Ugly Numbers的更多相关文章

  1. 丑数(Ugly Numbers, UVa 136)

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

  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. [POJ1338]Ugly Numbers

    [POJ1338]Ugly Numbers 试题描述 Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequ ...

  4. Ugly Numbers

    Ugly Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21918 Accepted: 9788 Descrip ...

  5. poj 1338 Ugly Numbers(丑数模拟)

    转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063? viewmode=contents 题目链接:id=1338&q ...

  6. leetcode@ [263/264] Ugly Numbers & Ugly Number II

    https://leetcode.com/problems/ugly-number/ Write a program to check whether a given number is an ugl ...

  7. Geeks Interview Question: Ugly Numbers

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

  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. linux系统定时任务crond入门

    1,Crond: Crond是linux系统中用来定期执行命令或指定程序任务的一种服务或者软件.(Centos5以后默认存在) 当优化开机自启动的时候,第一个就是crond. Crond服务默认情况( ...

  2. Swift学习笔记(7):函数

    目录: 函数参数与返回值 参数标签和参数名称 可变参数 传入传出参数 函数类型 嵌套函数 函数是一段完成特定任务的独立代码片段,使用func标示函数名,使用->标示返回类型. ・可以为函数参数设 ...

  3. WPF学习(一) - XAML

    Window.Grid.TextBox.Button等,都叫元素 xaml文档中,<>用来定义标签,标签可以用来描述元素或元素的属性,如: <Window> <Windo ...

  4. sql server 无法创建索引 因为对象名称和索引名称重复

    需求分析:如下图所示,给T_DD_OP1200_Final表的Id字段添加主键,保存时弹出 “T_DD_OP1200_Final”表- 无法创建索引“PK_T_DD_OP1200_Final”. 因为 ...

  5. 基于localStorage的登录注册

    以下代码,如果有地方有错,请直接指出,我会改进的(只改错误,不改逻辑,因为我自己是不会这样写代码的,这个只适合初学者): <!DOCTYPE html> <html> < ...

  6. Hibernate框架学习(一)——入门

    一.框架是什么 1.框架是用来提高开发效率的 2.封装好了一些功能,我们需要使用这些功能时,调用即可,不需要手动实现 3.框架可以理解成一个半成品的项目,只要懂得如何驾驭这些功能即可 二.hibern ...

  7. shell编程笔记1

    参考文章:1 http://blog.csdn.net/wuwenxiang91322/article/details/9259877   通过chmod改变文件权限 补充知识: 1Linux文件的三 ...

  8. hiho169周 - 表达式求值

    题目链接 计算表达式100*(2+12)-(20/3)*2 ---------------------------------------------------------------------- ...

  9. [TJOI2011]树的序(贪心,笛卡尔树)

    [TJOI2011]树的序 题目描述 众所周知,二叉查找树的形态和键值的插入顺序密切相关.准确的讲:1.空树中加入一个键值k,则变为只有一个结点的二叉查找树,此结点的键值即为k:2.在非空树中插入一个 ...

  10. Unity Microphone 无限时长录制

    原创文章:转载请标明出处--博客园 Jason_c Unity可以很方便的通过 Microphone.Start()方法来调用麦克风,但是有一个弊端是,必须传入时长,这就很尴尬了,因为大多数时间,我们 ...