PS/inflearn java coding2022. 4. 9. 12:32

import java.util.Scanner;

class Main {
	
	
	public static void main ( String args[]) throws Exception
	{
	
		Scanner in = new Scanner(System.in);
		
		
		 int n = in.nextInt();
		 
		 int cnt =0;
		 int [] ch = new int[n+1];
		 for ( int i = 2 ; i < n+1 ; i ++) {
			 
			 /* if ch[i] is empty prime number.*/
			 if ( ch[i] == 0 ) {
				 cnt++;
				 System.out.println("i: "+ i + " cnt : "+cnt);
				 for ( int j = i ; j < n+1 ;  j = j + i) {
					 ch [j] = 1;
				 }
			 }
			 
			 
			 
		 }
		
		
	}

}

'PS > inflearn java coding' 카테고리의 다른 글

초간단 스택  (0) 2022.04.10
멘토링  (0) 2022.04.09
임시반장  (0) 2022.04.09
봉우리  (0) 2022.04.09
factorial + memoization sample  (0) 2022.04.08
Posted by easy16