C++ isPrime()

1 개요[ | ]

C++ isPrime()
#include <iostream>
using namespace std;

bool isPrime(int x) {
    if(x < 2) return false;
    for(int i=2; i*i<=x; i++) {
        if(x%i == 0) return false;
    }
    return true;
}

int main() {
	for(int i=0; i<30; i++) {
		if(isPrime(i)) cout << i << ' '; // 2 3 5 7 11 13 17 19 23 29 
	}
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}