Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions suyeun84/202509/27 PGM LV2 멀쩡한 사각형.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
```java
class Solution {
public long solution(int w, int h) {
long answer = (long)w * (long)h;

long wl = (long)w / gcd(w, h);
long hl = (long)h / gcd(w, h);

answer -= (wl + hl - 1) * gcd(w, h);

return answer;
}

//최대 공약수 (유클리드 호제법)
private static long gcd(long w, long h) {
if(h == 0) {
return w;
}
return gcd(h, w % h);
}
}
```