1338 Ugly Numbers
来源:互联网 发布:nginx书籍 编辑:程序博客网 时间:2024/06/03 14:35
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.
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
1290
Sample Output
1210
DISCUSS:
#include <stdio.h>inline long min(long a,long b){return a>b?b:a;}int main(int argc, char *argv[]) { long buf[1500]={0},t2,t3,t5,num;int i=0,i2=0,i3=0,i5=0;buf[0]=1;for(i=1;i<1500;++i){t2=buf[i2]*2;t3=buf[i3]*3;t5=buf[i5]*5;buf[i]=min(min(t2,t3),t5);if(t2==buf[i])++i2;if(t3==buf[i])++i3;if(t5==buf[i]) ++i5;}while(scanf("%d",&num)!=EOF&&num)printf("%d\n",buf[num-1]);return 0;}
- problem 1338: ugly numbers
- pku 1338 Ugly Numbers
- POJ 1338 Ugly Numbers
- POJ 1338 Ugly Numbers
- POJ 1338 ugly numbers
- poj 1338 Ugly Numbers
- 1338 Ugly Numbers
- POJ 1338 Ugly Numbers
- POJ-1338-Ugly Numbers
- POJ 1338 Ugly Numbers
- poj-1338Ugly Numbers
- POJ 1338 - Ugly Numbers
- POJ 1338 Ugly Numbers
- poj 1338 ugly numbers
- Ugly Numbers(poj 1338)
- poj 1338 Ugly Numbers
- poj-1338-Ugly Numbers
- poj 1338 Ugly Numbers
- 黑客编程教程(十二)取得系统拥护权限
- 暑期总结——变是永远不变的
- java(Merge) 实现归并排序,快速排序
- 黑客编程教程(十三)多线程DOS程序
- 黑客编程教程(十四)单线程TCP端口扫描器
- 1338 Ugly Numbers
- 篮子放球问题(华为软件面试试题之一)
- addChild的使用 ——可视化对象
- hdu 1255
- 黑客编程教程(十五)HTTP代理
- 数字,字符串 和集合
- 黑客编程教程(十六)线程插入技术
- java实现栈的反转
- hdu 1542 Atlantis