//
R - Ugly Numbers
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
//
题意:只含有质因数 2 3 5 的数为丑数 求第 n 个丑数
//
题解:
01 由 素数分解唯一定理 可知 丑数的质因子只能有 2 3 5
02 要求丑数的位次 通过比较最小值 打表
// 判断是否为丑数
bool is_ugly( int n )
{
if( n<=0 ) return false;
while( n%2==0 ) n/=2;
while( n%3==0 ) n/=3;
while( n%5==0 ) n/=5;
return n==1; // 返回语句真假值
}
// 丑数打表
#include
using namespace std;
typedef unsigned long long ull;
const int MAXN=1e4+5;
int ans[MAXN];
int my_min( int a,int b,int c )
{
int temp=a