소수점 아래 숫자가 계속되지 않고 유한개인 소수를 유한소수라고 합니다. 분수를 소수로 고칠 때 유한소수로 나타낼 수 있는 분수인지 판별하려고 합니다. 유한소수가 되기 위한 분수의 조건은 다음과 같습니다.
두 정수 a와 b가 매개변수로 주어질 때, a/b가 유한소수이면 1을, 무한소수라면 2를 return하도록 solution 함수를 완성해주세요.
| A | B | result | 
|---|---|---|
| 7 | 20 | 1 | 
| 11 | 22 | 1 | 
| 12 | 21 | 2 | 
class Solution {
    public int solution(int a, int b) {
        int newB = b / gcd(a, b); 
        while (newB != 1) {
            if (newB % 2 == 0) newB /= 2;
            else if (newB % 5 == 0) newB /= 5;
            else return 2;
        }
        return 1;
    }
    private int gcd(int a, int b) {
        if (b == 0) return a;
        else return gcd(b, a % b);
    }
}