공부하는 히욤이

1945. 간단한 소인수분해 본문

Algorithm/SW Expert Academy

1945. 간단한 소인수분해

히욤이 2019. 1. 25. 00:01

SW Expert 1989. 초심자의 회문 검사

문제의 저작권은 SW Expert에 있습니다 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.util.Scanner;
public class Solution {
 
 
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        for(int test_case = 1; test_case <= T; test_case++) {
            int n = sc.nextInt();
            int a = 0//2
            int b = 0//3
            int c = 0//5
            int d = 0//7
            int e = 0//11
 
            while (true) {
                if (n%2 ==0) { //입력 받은 값에 해당 숫자를 나눈 나머지가 0이면 
                    a++//소인수 분해에 해당한다는 뜻임으로 1증가
                    n= n/2//n은 n과 해당 숫자를 나눈 값으로 초기화 해준다
                } else if (n%3 == 0) {
                    b++;
                    n= n/3;
                } else if (n%5 == 0) {
                    c++;
                    n= n/5;
                } else if (n%7 == 0) {
                    d++;
                    n= n/7;
                } else if (n%11 == 0) {
                    e++;
                    n= n/11;
                }
                if (n==1) {
                    break;
                }
            }
            System.out.println("#" + test_case +" " + a + " " ++ " " + c +" "+ d + " "+ e);
        }
        sc.close();
    }
}
cs