2 3 5 循环
第一份代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<stdio.h> 2 int main() 3 { 4 printf("The 1500'th ugly number is 859963392. "); 5 return 0; 6 }
第二份
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 using namespace std; 3 #include<stdio.h> 4 #include<string.h> 5 #include<math.h> 6 #include<stack> 7 int min(int a,int b) 8 { 9 return a<b?a:b; 10 } 11 int main() 12 { 13 long long a[1500]; 14 long long a2=0,a3=0,a5=0,min1,i; 15 a[0]=1; 16 for(i=1;i<1500;i++) 17 { 18 while(a[a2]*2<=a[i-1]) 19 a2++; 20 while(a[a3]*3<=a[i-1]) 21 a3++; 22 while(a[a5]*5<=a[i-1]) 23 a5++; 24 min1=min(min(a[a2]*2,a[a3]*3),a[a5]*5); 25 a[i]=min1; 26 } 27 cout<<"The 1500'th ugly number is "<<a[1499]<<"."<<endl; 28 return 0; 29 }