U E D R , A S I H C RSS

Ugly Numbers/송지훈

  • 함. 1500 1
.
  • 2, 3, 5 .

. 900 2 ,
1000 7 ...

1500 ... 76 ...

#include <iostream>
#include <ctime>
using std::cout;
using std::cin;
using std::endl;
using std::clock_t;

#define LIMIT 1500                      // 

int main() {
	int arr[LIMIT] = {0}, num, index = 0, target;
	clock_t start,end;              //     .
	target = 1500;                  // 1500    .

	start = clock();                // .
	for(int i = 1;arr[target-1] == 0;i++) {
		num = i;
		while((num % 2) == 0) {
			num /= 2;
		}
		while((num % 3) == 0) {
			num /= 3;
		}
		while((num % 5) == 0) {
			num /= 5;
		}
		if(num == 1) {          // 2, 3, 5    1 .
			arr[index] = i; //  1   .
			index++;
		}
	}
	end = clock();                  //  .

	cout << "Run time = " << (double)(end-start)/CLK_TCK << endl
		 << arr[target-1] << endl;
	return 0;
}


sorting .


.

2, 3, 5
30 ...



... 하 ...
...

... .
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:19
Processing time 0.0203 sec