Ugly Numbers

Time Limit: 1000MS Memory Limit: 10000K

Total Submissions: 21918 Accepted: 9788

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, …

shows the first 10 ugly numbers. By convention, 1 is included.

Given the integer n,write a program to find and print the n’th ugly number.

Input

Each line of the input contains a postisive integer n (n <= 1500).Input is terminated by a line with n=0.

Output

For each line, output the n’th ugly number .:Don’t deal with the line with n=0.

Sample Input

1

2

9

0

Sample Output

1

2

10

Source

New Zealand 1990 Division I,UVA 136

打表记录即可

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define LL long long
using namespace std; const LL MAX = 1e15; LL a[15500];
int main()
{
LL b,c,d;
int top=0;
//freopen("output.txt","w",stdout);
for(int i=0;i<=30;i++)
{
if(i==0)
{
b=1;
}
else
{
b*=2;
}
if(b>MAX)
{
break;
}
for(int j=0;j<=30;j++)
{
if(j==0)
{
c=1; }
else
{
c*=3;
}
if(b*c>MAX)
{
break;
}
for(int k=0;k<=30;k++)
{
if(k==0)
{
d=1;
}
else
{
d*=5;
}
if(b*c*d>MAX)
{
break;
}
a[top++]=b*c*d;
//printf("%lld\n",b*c*d);
}
}
}
sort(a,a+top);
int n;
while(scanf("%d",&n)&&n)
{
printf("%lld\n",a[n-1]);
}
return 0;
}

Ugly Numbers的更多相关文章

  1. [POJ1338]Ugly Numbers

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

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

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

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

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

  5. 136 - Ugly Numbers

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

  6. Ugly Numbers(STL应用)

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

  7. 丑数(Ugly Numbers, UVa 136)

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

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

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

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

随机推荐

  1. CocoaPods看的三篇文章

    http://www.bubuko.com/infodetail-425274.html//有图片 http://www.cnblogs.com/jys509/p/4839803.html http: ...

  2. M面经Prepare: Find integer Average of 2 integers.

    The definition of integer average is the highest smaller integer if average is floating point number ...

  3. Android遇到的错误,运行时崩溃

    修改主题背景时在<Activity>中增加android:theme="@android:style/Theme.Black.NoTitleBar"时运行 出现崩溃的现 ...

  4. Eclipse 文本显示行号

  5. 使用 GitHub / GitLab 的 Webhooks 进行网站自动化部署

    老早就想写这个话题了,今天正好有机会研究了一下 git 的自动化部署.最终做到的效果就是,每当有新的 commit push 到 master 分支的时候,就自动在测试/生产服务器上进行 git pu ...

  6. paper 77:[转载]ENDNOTE使用方法,常用!

    一.简介  EndNote是一款用于海量文献管理和批量参考文献管理的工具软件,自问世起就成为科研界的必备武器.在前EndNote时代,文献复习阶段从各大数据库中搜集到的文献往往千头万绪.或重复或遗漏, ...

  7. Oracle存储过程总结

    1.存储过程结构 1.1 第一个存储过程 create or replace procedure proc1( para1 varchar2, para2 out varchar2, para3 in ...

  8. 夺命雷公狗---Thinkphp----4之数据表的设计

    我们这次来写的项目是仿http://yispace.net/39765.html而写的, 这里其实也就那回事,主要有标题和内容,和栏目, 文章页就更加的简单,其实也就那及格字段即可,我们分享得出的结果 ...

  9. update表关联

    第一种: update student set student.age =(select `user`.age from user where id=student.id ) where studen ...

  10. 使用uiautomatorviewer和uiautomator来做android的UI测试

    来自:http://university.utest.com    作者:Angelos Nakulas (All Authored Courses)      译者:Elaine00 目录 简介 什 ...