只包含因子2、3、5的数称作丑数。
#include <iostream>
#include <vector>
using namespace std; int GetUglyNumber(int n)
{
if(n <= )
return ; vector<int> UglyNum(n, );
UglyNum[] = ; vector<int>::iterator it2 = UglyNum.begin();
vector<int>::iterator it3 = UglyNum.begin();
vector<int>::iterator it5 = UglyNum.begin(); int nextIndex = ;
while(nextIndex < n)
{
int nextMin = min((*it2) * , min((*it3) * , (*it5) * ));
UglyNum[nextIndex] = nextMin; while((*it2) * <= UglyNum[nextIndex])
it2++;
while((*it3) * <= UglyNum[nextIndex])
it3++;
while((*it5) * <= UglyNum[nextIndex])
it5++; nextIndex++;
} return UglyNum[nextIndex - ];
} int main()
{
cout<<GetUglyNumber()<<endl;
}