Ugly Numbers
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的更多相关文章
- [POJ1338]Ugly Numbers
[POJ1338]Ugly Numbers 试题描述 Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequ ...
- poj 1338 Ugly Numbers(丑数模拟)
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063? viewmode=contents 题目链接:id=1338&q ...
- 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 ...
- 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, ...
- 136 - Ugly Numbers
Ugly Numbers Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3 ...
- Ugly Numbers(STL应用)
题目链接:http://poj.org/problem?id=1338 Ugly Numbers Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
- 丑数(Ugly Numbers, UVa 136)
丑数(Ugly Numbers, UVa 136) 题目描述 我们把只包含因子2.3和5的数称作丑数(Ugly Number).求按从小到大的顺序的第1500个丑数.例如6.8都是丑数,但14不是,因 ...
- 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, ...
随机推荐
- switch为什么不能用string类型?
switch()括号里面的参数是一个int型值啊 你要可以转换为int型的参数才行得通啊
- JAVA JDBC连接 SQLServer2012 连接失败 端口号错误
SQLServer2012的SQL Sever 网络配置 我有4个 SQLEXPRESS的协议 SQLSERVER2008的协议 MSSQLSERVER的协议 SQLSERVER2012的协议 他们都 ...
- 数dp多少个0-n多少0-9
#include <bits/stdc++.h> using namespace std; const int N = 15; int n; int dp[N][N][N]; int a[ ...
- [编辑] 分享一些java视频
1.官网:http://www.atguigu.com/,导航栏视频下载,根据自己的需求下载,对应的视频,其次可以下载相应的文档. 2.百度网盘: 链接: http://pan.baidu.com/s ...
- Python学习总结7:随机字符串和随机数
Python生成随机数与随机字符串,需要import random模块.random模块最常用的几个函数如下: 1. random.random(a, b) 用于生成一个0到1的随机符点数: 0 &l ...
- SQL静态
静态 1.普通成员普通成员都是属于对象的用对象调用 2.静态成员静态成员是属于类的用类名调用 class FenBi{public int length;//普通成员public string col ...
- hdu5322 Hope
设dp[n]为n个数字排列时候的答案,那么可以得到dp方程 dp[n]=Σdp[n-i]*c(n-1,i-1)*(i-1)!*i^2(1<=i<=n) 然后上式可以化成卷积形式,分治FFT ...
- java 枚举类小结 Enum
好久没有接触枚举类了,差不多都忘了,今天抽出个时间总结一下吧.说实话,枚举类确实能够给我们带来很大的方便. 说明:枚举类它约定了一个范围,可以理解成只可以生成固定的几个对象让外界去调用,故枚举类中的构 ...
- XMLHttpRequest Level2实现跨域
Html5提供的XMLHttpRequest Level2已经实现的跨域访问以及一些新功能 1.ie10以下版本不支持 2.在服务器端做一些小改动即可: header("Access-Con ...
- OpenGl And 视图
OpenGl And 视图 标签(空格分隔): game 简介 本文主要介绍坐标系的观念, 以及在openGL中的视图及其相关的变换. 大纲 视图.模型.投影变换概念 Opengl中对各种变换的支持 ...