멀쩡한 사각형

LJM·2023년 8월 17일
0

programmers

목록 보기
63/92
class Solution {
    public long solution(int w, int h) {
        
        long answer = (long)w*h - (w + h - gcd(w, h));
        return answer;
    }
    
    public int gcd(int a, int b)
    {
        if(b>a){
            int temp = a;
            a = b;
            b = temp;
        }
        
        int r = 0;
        while(b!=0)
        {
            r = a%b;
            a = b;
            b = r;
        }
        return a;
    }
}
profile
게임개발자 백엔드개발자

0개의 댓글