Deep_Dev

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AV_6mRsasV8DFAWS&categoryId=AV_6mRsasV8DFAWS&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=3&pageSize=30&pageIndex=5 

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

 


 

๋ฒ”์œ„๊ฐ€ ๋„“์„๋•Œ ์†Œ์ˆ˜ ๊ตฌํ•˜๊ธฐ : ์—๋ผํ† ์Šคํ…Œ๋„ค์Šค์˜ ์ฒด

 

๋ฐฐ์—ด์„ ๋™์ ๋ฐฐ์—ดํ•ด์ฃผ์–ด ๋ชจ๋“ ๊ฐ’์„ 0์œผ๋กœ ์„ธํŒ…ํ•˜๊ณ 

์ฒซ ์†Œ์ˆ˜ 2๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์—ฌ, ํ•ด๋‹น ์ธ๋ฑ์Šค์˜ ๊ฐ’์ด 0์ด๋ฉด ์†Œ์ˆ˜, ๊ทธ๋ฆฌ๊ณ  ํ•ด๋‹น ๊ฐ’์˜ ๋ฐฐ์ˆ˜๋“ค์„ ๋ชจ๋‘ 1๋กœ ๋ฐ”๊พผ๋‹ค.

 

 

import java.util.Scanner;
class Solution{
    public static void main(String args[]) throws Exception{
        Scanner kb=new Scanner(System.in);
        int[] arr=new int[1000000+1];
        for(int i=2; i<arr.length; i++){
            if(arr[i]==0){
                System.out.print(i+" ");
                for(int j=i; j<arr.length; j+=i)
                    arr[j]=1;
            }
        }
    }
}