==== 소감 ==== 2005/02/18 Accepted 0:00.006 64 접근 방법을 바꾼후 쉽게 풀린 문제. 지수의 조합을 이용. ==== Ugly Number ==== {{{~cpp // no136 - Ugly Numbers(a) #include #include #include using namespace std; const int MAX = 2000; inline int comp(const void *i,const void *j) { return *(int *)i-*(int *)j; }; int main() { int num[MAX]; int count = 0; int expo2, expo3, expo5; int MAX_INT = pow(2,31) - 1; for (expo5=0; expo5<13; expo5++) { for (expo3=0; expo3<19; expo3++) { for (expo2=0; expo2<30; expo2++) { if (expo5 + expo3 + expo2 > 29) break; if (pow(2,expo2) * pow(3,expo3) * pow(5,expo5) > MAX_INT || pow(2,expo2) * pow(3,expo3) * pow(5,expo5) < 0) break; num[count++] = pow(2,expo2) * pow(3,expo3) * pow(5,expo5); } } } qsort(num, count, sizeof(int), comp); cout << "The 1500'th ugly number is " << num[1499] << ".\n"; return 0; } }}} ---- [UglyNumbers] [문보창]