Ugly Numbers(丑数)
来源:互联网 发布:好喝的白酒推荐知乎 编辑:程序博客网 时间:2024/06/05 00:17
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
1290Sample Output
1210
#include <iostream>#include <string.h>#include <cstdio>#include <algorithm>#include <string>using namespace std;long long min(long long a,long long b,long long c){ long long x=a<b?a:b; return x<c?x:c;}int main(){ long long num[1505]; long long p2,p3,p5; p2=p3=p5=1; memset(num,0,sizeof(num)); num[1]=1; int i=1; while(i<=1501){ num[++i]=min(num[p2]*2,num[p3]*3,num[p5]*5);if(num[i]==num[p2]*2) p2++;if(num[i]==num[p3]*3) p3++;if(num[i]==num[p5]*5) p5++; } int n; while(scanf("%d",&n)&&n){printf("%lld\n",num[n]); } return 0;}
0 0
- Ugly Numbers(丑数)
- 丑数 Ugly Numbers
- Ugly Numbers --丑数
- POJ 1338 Ugly Numbers(丑数)
- poj1338 Ugly Numbers(丑数模拟)
- UVA136 - Ugly Numbers(丑数)
- NYOJ1097 Ugly Numbers 【丑数】
- 158ugly numbers丑数
- Ugly Numbers(POJ1338)(丑数,技巧性强)
- poj 1338 Ugly Numbers(丑数模拟)
- POJ 1338 Ugly Numbers 寻找丑数
- POJ-1338-Ugly Numbers-丑数
- POJ1338 Ugly Numbers 丑数 [数论]
- 1.5.8丑数(Ugly Numbers)
- POJ 1338 Ugly Numbers(丑数)
- Ugly Numbers UVA 136 丑数
- Uva 136 Ugly Numbers(丑数)
- Ugly Number(丑数)
- HDU1754线段树单点更新
- vim配置文件
- hdfs java.io.IOException: Mkdirs failed to create
- include使用“”还是<>?
- sqlite3 初接触
- Ugly Numbers(丑数)
- ORACLE禁用启用触发器
- wsgi是什么
- 怎样找回照相机中已经删除的照片,数码相机照片数据删除怎么恢复
- Android-10-拨号器
- 免费使用Adobe Flash Builder 4.5方法 不用注册码
- openwrt 有线无线配置
- Error injecting constructor, java.net.UnknownHostException: *****
- HDU 1385 Minimum Transport Cost (最短路+记录路径+字典序)