~cpp 
#include <iostream>
#include <time.h>
using namespace std;

int main() {
	int primeNumber[100000];
	primeNumber[0] = 2;
	int arrLength = 1;
	bool isPrimeNumber = true;

	time_t start, end;

	start = clock();

	cout << "2" << endl;
	for (int i = 3 ; i < 500000 ; i += 2) {
		for (int j = 1 ; j < arrLength+1 ; j++) {
			if ( i % primeNumber[j] == 0 ) {
				isPrimeNumber = false;
				break;
			}
		}
		if (isPrimeNumber) {
			primeNumber[arrLength++] = i;
			printf("%d\n", i);
		}
		isPrimeNumber = true;
	}
	end = clock();
	cout << (end - start)/CLK_TCK << endl;
	return 0;
}
----
소수구하기
Retrieved from http://wiki.zeropage.org/wiki.php/소수구하기/상욱
last modified 2021-02-07 05:30:13