휴지통/알고리즘 & 자료구조
멀쩡한 사각형
신재권
2022. 6. 23. 01:57
package programmers;
import java.math.BigInteger;
public class PlainSquare {
public static long solution(int w, int h) {
int gcd = BigInteger.valueOf(w).gcd(BigInteger.valueOf(h)).intValue();
return ((long)w * (long)h) - ((((long)w / gcd) + ((long)h / gcd) - 1) * gcd);
}
}