Skip to content

Commit 3c68076

Browse files
authored
Merge pull request #991 from AlgorithmWithGod/suyeun84
[20250927] PGM / LV2 / 멀쩡한 사각형 / 김수연
2 parents 02c6d32 + ab5a675 commit 3c68076

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
```java
2+
class Solution {
3+
public long solution(int w, int h) {
4+
long answer = (long)w * (long)h;
5+
6+
long wl = (long)w / gcd(w, h);
7+
long hl = (long)h / gcd(w, h);
8+
9+
answer -= (wl + hl - 1) * gcd(w, h);
10+
11+
return answer;
12+
}
13+
14+
//최대 공약수 (유클리드 호제법)
15+
private static long gcd(long w, long h) {
16+
if(h == 0) {
17+
return w;
18+
}
19+
return gcd(h, w % h);
20+
}
21+
}
22+
```

0 commit comments

Comments
 (0)