728x90
SMALL

using System;

public class Solution {
    public int solution(int a, int b) {
        int answer = 1;


        while(b % 2 == 0)
        {
            b /= 2;
        }


        while(b % 5 == 0)
        {
            b /= 5;
        }


        if(a % b != 0)
        {
            answer = 2;
        }
        return answer;
    }
}

 

 

자바

 

class Solution {
    public int solution(int a, int b) {
        int answer = 0;

        for (;b%2 == 0;) 
        {
            b = b/2;
        }
        
        for (;b%5 == 0;) 
        {
            b = b/5;
        }

        if ((a/(double)b)%1 == 0) 
        {
            answer = 1;
        } 
        else 
        {
            answer = 2;
        }

        return answer;
    }
}

 

 

class Solution {
    public int solution(int a, int b) {
        int answer = 1;
        int max = 0;
        
        for(int i =1; i<=a; i++)
        {
            if(a%i ==0 && b%i ==0) 
              max= i;
        }

        b /= max;

        while(b>1)
        {
            if(b%2==0)
            {
                b /= 2;
            }
            else if(b%5==0)
            {
                b /= 5;
            }
            else 
            {
                return 2;
            }
        }

        return answer;
    }
}

 

728x90

설정

트랙백

댓글