poj-1338-Ugly Numbers
来源:互联网 发布:淘宝cpu散片哪家好 编辑:程序博客网 时间:2024/05/20 20:21
Ugly Numbers
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 20880 Accepted: 9268
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
#include<iostream>#include<algorithm>using namespace std;int a[1502]={0,1};int main(){ int num2=2,num3=3,num5=5; int i=1,j=1,k=1; int t=0,s; for(s=2;s<1501;++s) { t=min(num2,min(num3,num5)); a[s]=t; if(t==num2) num2=a[++i]*2; if(t==num3) num3=a[++j]*3; if(t==num5) num5=a[++k]*5; } while(cin>>s&&s) cout<<a[s]<<endl; return 0;}
0 0
- POJ 1338 Ugly Numbers
- POJ 1338 Ugly Numbers
- POJ 1338 ugly numbers
- poj 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
- poj-1338-Ugly Numbers
- poj-1338-Ugly Numbers
- poj 1338 Ugly Numbers
- 10款超赞的深色UI控件素材下载
- js中字符替换函数String.replace()使用技巧
- hdu_1087_jump_DP
- 排序算法总结---希尔排序
- 黑马程序员——Java基础---泛型和反射
- poj-1338-Ugly Numbers
- php注释标准
- poj-1338-Ugly Numbers
- Eclipse快捷键大全(转载)
- scsi debugging
- 一种减少索引下载/切换总时间的技巧
- MVC4 apiController 过滤器ActionFilterAttribute的注意事项
- 多线程总结(代码)
- 【SSH三大框架】Spring基础第一篇:搭建Spring环境、实例化Bean、管理Bean的作用域以及Bean的生命周期