# ★★★☆☆ 멀쩡한 삼각형
# 구현코드
class Solution {
public long solution(int w, int h) {
long answer = 1;
int gcd = gcd(w, h);
long remove = ((h / gcd) + (w / gcd) - 1) * gcd;
answer = ((long)w * (long)h) - remove;
return answer;
}
public int gcd(int a, int b) {
if (a % b == 0)
return b;
else
return gcd(b, a % b);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16