[백준/자바] 11653번 : 소인수분해
·
자바/백준 알고리즘(자바)
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 answer = new ArrayList(); while(N>1) { if(N%i==0) { answer.add(i); N = N/i; }else { i++; } } for(int num: answer) { System.out.println(num); } } }