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, ...
随机推荐
- linux:问题
1>.Xshell远程连接linux闲置时间过长会自动中断连接: 2>.在linux环境下乱码: 3>.在linux下面执行mv /bin/ls /root/bin之后执行ls就不能 ...
- PostgreSQL9.1 upgrade to PostgreSQL9.5rc1
PostgreSQL9.1.0 upgrade to PostgreSQL9.5rc1 安装PG9.1端口为5432 [pgup@minion1 pg]$ ls postgresql-9.1.0.ta ...
- c语言的一些库
1利用DEv编程的时候遇见sleep函数 ..注意S大写,并添加#include<windows.h>.
- 批量文本读取URL获取正常访问且保留对应IP
#coding=utf-8 import sys import requests for i in range(3000,4999,1): url = 'http://192.168.88.139:8 ...
- Java基础(46):选择排序的Java封装(完整可运行)
1 package lsg.ap.select; import java.util.Random; public class SelectSort { //选择排序 /** *@author: 梁山广 ...
- Java基础(4):Scanner输入的典型应用
import java.util.Scanner; /* * 功能:为指定的成绩加分,直到分数大于等于60为止 * 输出加分前的成绩和加分后的成绩,并且统计加分的次数 * 步骤: * 1.定义一个变量 ...
- 动画--过渡延迟时间 transition-delay
transition-delay属性和transition-duration属性极其类似,不同的是transition-duration是用来设置过渡动画的持续时间,而transition-delay ...
- sql 去除列中内容的单引号
update [dbo].[历史数据补全$] set bankCardNo=replace(bankCardNo,'''','') 总共4个单引号,外边2个是字符串固有的2个,里边两个就表示是一 ...
- 导出Excel offer2007以上
package cn.knet.data.untils; import java.awt.Color; import java.io.File; import java.io.FileOutputSt ...
- 夺命雷公狗---DEDECMS----1dedecms的安装过程
我们这次要玩的dedecms(cms也就是内容管理系统),电商网.或者政府网..小说网.新闻网之类的都是基于可以用cms来实现的. 现在在市场上主流的cms系统有dedecms(织梦),帝国cms,p ...