__int64 GetUglyNum( int n0 )
{
if( n0 < 1 )
{
return 0;
}
//int *pNum = new int[n0];
__int64 *pNum = new __int64[n0];
for( int i=0; i<n0; ++i )
{
pNum[i] = 1;
}
int *pIndex = new int[n0];
for( int i=0; i<n0; ++i )
{
pIndex[i] = i;
}
pNum[0] = 2;
pNum[1] = 3;
pNum[2] = 4;
pNum[3] = 5;
pIndex[0] = 1;
for( int i=4; i<n0; ++i )
{
__int64 min = pNum[0]*pNum[ pIndex[0] ];
while( min <= pNum[i-1] )
{
pIndex[0]++;
min = pNum[0]*pNum[ pIndex[0] ];
}
int minIndex = 0;
//cout << min << endl;
for( int j=1; j<i; ++j )
{
_int64 temp = pNum[j]*pNum[ pIndex[j] ];
if( temp<min && temp>pNum[i-1] )
{
min = temp;
minIndex = j;
}
}
pIndex[minIndex]++;
pNum[i] = min;
//cout << pNum[i] << " ";
}
__int64 result = pNum[n0-1];
delete []pNum;
delete []pIndex;
return result;
}
void TestUglyNum()
{
cout << GetUglyNum( 1500 ) << endl;
}