Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

소수구하기/인수

From ZeroWiki
  • 애들 시키려고 만들었음
  • printf가 좀더 빠르다.
#include <stdio.h>
#include <cmath> 
#include <ctime> 

bool IsPrime(int n) 
{ 
	for(int j = 3 ; j <= sqrt(n) ; j+=2) 
	{ 
		if(n % j == 0) 
			return false; 
	} 
	return true; 
} 

int main() 
{ 
	printf("%d %d",2,3); 
	for(int i = 5 ; i <= 50000 ; i+=2) 
	{ 
		if(i % 3 == 0) 
			continue; 
		else if(IsPrime(i)) 
			printf("%d ",i); 
	}        
	return 0; 
}

소수구하기