자바/백준 알고리즘(자바)

[백준/자바] 11653번 : 소인수분해

Heeyeon Choi 2021. 12. 16. 09:14
728x90
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);		
		
		int N = in.nextInt();
		int i=2;
		ArrayList<Integer> answer  = new ArrayList<Integer>();
		
		while(N>1) {
			
			if(N%i==0) {
				
				answer.add(i);
				N = N/i;
				
			}else {
				i++;
			}
			
		}	
		
		
		for(int num: answer) {
			
			System.out.println(num);
		}
	}
}
728x90

 

728x90