본문 바로가기

Java/SWEA

[JAVA] SWEA 1945. 간단한 소인수분해

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5Pl0Q6ANQDFAUq&categoryId=AV5Pl0Q6ANQDFAUq&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=JAVA&select-1=2&pageSize=10&pageIndex=2

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

 

정답 

 

import java.util.*;

class Solution {    
    
    public static void main(String args[]) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt(); 
        
        for (int t = 1; t <= T; t++)
        { 
            int N = sc.nextInt();
            
            int decimal[] = {2,3,5,7,11};
            int answer[] = new int[5];
           
            for(int i=0; i<5; i++)
            {
            	while(true)
            	{
            		if(N%decimal[i]==0)
            		{
            			answer[i]++;
            			N=N/decimal[i];
            		}
            		else
            		{
            			break;
            		}
            	}
            }
            
            System.out.printf("#%d ",t);
            for(int i=0; i<answer.length; i++)
            {
            	System.out.print(answer[i]+" ");
            }
            System.out.println();
            
        }
    }
}