본문 바로가기
Algorithm/Baekjoon Online Judge

[Java] [Math] 백준 11653 소인수 분해 브론즈1

by 제우제우 2024. 5. 4.

https://www.acmicpc.net/problem/11653

import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringBuilder sb = new StringBuilder();

        for (int i = 2; i * i <= n; i++) {
            while (n % i == 0){
                sb.append(i).append("\n");
                n /= i;
            }
        }
        if(n != 1) sb.append(n);
        System.out.println(sb);
    }
}