baekjoon 11653

0_23·2022년 11월 28일
0

[BOJ][Java]

목록 보기
32/55
post-thumbnail

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int N = Integer.parseInt(br.readLine());
        while(true){
            boolean isPrime = true;
            for(int j=2; j*j<=N && isPrime;j++){
                if(N%j==0) {
                    bw.write(j + "\n");
                    N /= j;
                    isPrime = false;
                }
            }
            if(isPrime&&N>1){
                bw.write(N + "\n");
                break;
            }else if(isPrime&&N==1){
                break;
            }
        }
        bw.flush();
        br.close();
        bw.close();
    }
}

0개의 댓글