We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b1412f9 commit ab5a675Copy full SHA for ab5a675
1 file changed
suyeun84/202509/27 PGM LV2 멀쩡한 사각형.md
@@ -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