프로그래머스-멀쩡한 사각형

이호영·2022년 4월 5일
0
class Solution {
    public long solution(int w, int h) {
        int wt = w;
        int ht = h;
        long answer = w;
        
        // 유클리드 호제법
        while(ht!=0){
    		int r = wt%ht;
    		wt = ht;
    		ht = r;
    	}
        
        answer *= h;
        answer -= (w+h-wt);
        return answer;
    }
}

0개의 댓글