[Programmers] 멀쩡한 사각형 (62048번) - Java Solution
문제
- https://programmers.co.kr/learn/courses/30/lessons/62048
Solution
class Solution {
public long solution(int w, int h) {
int gcd = getGcd(w, h);
return (long)w*h - ((w/gcd)+(h/gcd)-1)*(long)gcd;
}
public int getGcd(int w, int h) {
if(h == 0) {
return w;
}
return getGcd(h, w%h);
}
}
참고한 글
- velog.io/@ajufresh글
- https://mainia.tistory.com/2000
Leave a comment