POJ1338 Ugly Numbers
来源:互联网 发布:快递单号记录软件 编辑:程序博客网 时间:2024/06/02 13:22
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.
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.
Each line of the input contains a postisive integer n (n <= 1500).Input is terminated by a line with n=0.
For each line, output the n’th ugly number .:Don’t deal with the line with n=0.
1290
1210
将2,3,5进行排列组合树1到1500之间的各个数(y=(2^a)*(3^b)*(5^c))
AC代码:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){int n;while(~scanf("%d",&n)&&n){int a[1501],i,p2=1,p3=1,p5=1,x;a[1]=1;for(i=2;i<=1500;i++){x=min(min(a[p2]*2,a[p3]*3),a[p5]*5);a[i]=x;if(x==a[p2]*2) p2++;if(x==a[p3]*3) p3++;if(x==a[p5]*5) p5++;}printf("%d\n",a[n]);}return 0;}
0 0
- poj1338(Ugly Numbers)
- poj1338 Ugly Numbers(技巧)
- 枚举 poj1338 Ugly Numbers
- POJ1338 Ugly Numbers
- poj1338 Ugly Numbers
- POJ1338 Ugly Numbers
- POJ1338 Ugly Numbers
- poj1338——Ugly Numbers
- UVA 136 & POJ1338 Ugly Numbers
- POJ1338 Ugly Numbers 丑数 [数论]
- poj1338 Ugly Numbers(set + 优先队列)
- POJ1338 Ugly Numbers(解法二)
- poj1338 Ugly Numbers(丑数模拟)
- POJ1338 Ugly Numbers 堆优化+模拟
- Ugly Numbers(POJ1338)(丑数,技巧性强)
- 【日常学习】【优先队列】POJ1338 Uva136 - Ugly Numbers题解
- poj1338 ugly number 题解 打表
- Ugly Numbers
- LeetCode_461-hamming distance
- mqtt发布端代码
- 结构体占用字节数及存储与空间分配(转)
- manifest.xml微擎系统模块的安装文件内容
- 华为OJ 字符串运用-密码截取
- POJ1338 Ugly Numbers
- Probabilistic decoder, Bayesian neural network, Probabilistic encoder
- java学习
- 通过jdbc访问mysql数据库的具体过程及简单查询
- leetcode_169. Majority Element
- leetcode#121#122#123 Best Time to Buy and Sell Stock
- Mysql5.7安装初始化
- Linux基本分区管理
- Android 6.0.1选取本地图片操作时报No Activity found to handle intent错误