본문 바로가기
Java/Programmers

[Lv.0]유한소수 판별하기

by GLOWWW 2023. 1. 17.

public class 유한소수판별하기 {
    public static int GCD(int a, int b) {
        if (a % b == 0) {
            return b;
        }
        return GCD(b, a % b);
    }
    public static int solution(int a, int b) {
        int gcd_num = GCD(a, b);
        int btm = b / gcd_num;
        while (btm != 1) {
            if (btm % 2 == 0) {
                btm /= 2;
            } else if (btm % 5 == 0) {
                btm /= 5;
            } else {
                return 2;
            }
        }


        return 1;
    }

    public static void main(String[] args) {
        int result = solution(7, 20);
        System.out.println(result);
    }
}

'Java > Programmers' 카테고리의 다른 글

[Lv.0]특이한 정렬  (0) 2023.01.17
[Lv.0]등수 매기기  (0) 2023.01.17
[Lv.0]문자열 밀기  (0) 2023.01.17
[Lv.0]직사각형 넓이 구하기  (1) 2023.01.17
[Lv.0]캐릭터의 좌표  (0) 2023.01.17

댓글