본문 바로가기
Java/SW Expert Academy

1945. 간단한 소인수분해

by GLOWWW 2021. 1. 11.
package oSWExpertAcademy;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class D2_1945 {
    public static void main(String[]args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int testCount = Integer.parseInt(br.readLine());
            for(int tc=1; tc<=testCount; tc++) {
                int a = 0;
                int b = 0;
                int c = 0;
                int d = 0;
                int e = 0;
                int input = Integer.parseInt(br.readLine());
                while(input%2 == 0) {
                    input /= 2;
                    a++;
                }
                while(input%3 == 0) {
                    input /= 3;
                    b++;
                }
                while(input%5 == 0) {
                    input /= 5;
                    c++;
                }
                while(input%7 == 0) {
                    input /= 7;
                    d++;
                }
                while(input%11 == 0) {
                    input /= 11;
                    e++;
                }
                System.out.println("#"+tc+" "+a+" "+b+" "+c+" "+d+" "+e);
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

'Java > SW Expert Academy' 카테고리의 다른 글

1928. Base64 Decoder  (0) 2021.01.12
1940. 가랏! RC카!  (0) 2021.01.11
1946. 간단한 압축 풀기  (0) 2021.01.11
1948. 날짜 계산기  (0) 2021.01.11
1954. 달팽이 숫자  (0) 2021.01.11

댓글