public long solution(int w, int h) {
long area = (long) w * h;
if (w == 1 || h == 1) {
return 0;
}
long gcd = calculateGcd(w, h);
long overlappedArea = (w / gcd) + (h / gcd) - 1;
return area - gcd * overlappedArea;
}
public long calculateGcd(long a, long b) {
if (b == 0) {
return a;
}
return calculateGcd(b, a % b);
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/62048