SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
www.swexpertacademy.com
풀이
- 2,3,5,7,11이 계속 나누어 떨어질 때까지 각 변숫값(a, b, c, d, e)을 증가시킨다.
import java.io.*;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
for(int tc=1; tc<=T; tc++) {
int N = Integer.parseInt(br.readLine());
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int tmp = N;
while(tmp%2 == 0) {
a++;
tmp /= 2;
}
tmp = N;
while(tmp%3 == 0) {
b++;
tmp /= 3;
}
tmp = N;
while(tmp%5 == 0) {
c++;
tmp /= 5;
}
tmp = N;
while(tmp%7 == 0) {
d++;
tmp /= 7;
}
tmp = N;
while(tmp%11 == 0) {
e++;
tmp /= 11;
}
System.out.println("#"+tc+" "+a+" "+b+" "+c+" "+d+" "+e);
}
}
}
'SWEA > D2' 카테고리의 다른 글
| [SWEA] 1859. 백만 장자 프로젝트 (1) | 2019.05.16 |
|---|---|
| [SWEA] 1940. 가랏! RC카! (0) | 2019.05.14 |
| [SWEA] 1946. 간단한 압축 풀기 (0) | 2019.05.14 |
| [SWEA] 1948. 날짜 계산기 (0) | 2019.05.14 |
| [SWEA] 1954. 달팽이 숫자 (0) | 2019.05.14 |