SWEA/D2
[SWEA] 1945. 간단한 소인수분해
둘기친구
2019. 5. 14. 14:06
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); } } }