728x90
package prog;
public class 멀쩡한_사각형 {
public static void main(String[] args) {
Solution_멀쩡한_사각형 s = new Solution_멀쩡한_사각형();
System.out.println(s.solution(8 ,12));
System.out.println(s.solution(2 ,3));
}
}
class Solution_멀쩡한_사각형{
public long solution(int w, int h) {
long answer = 1;
answer=(long)w*h - (w+h-gcd(w,h));
return answer;
}
public static int gcd(int a, int b) {
while(b!=0){
int r = a%b;
a= b;
b= r;
}
return a;
}
}
728x90
'알고리즘 > 프로그래머스' 카테고리의 다른 글
기능개발 (자바) (0) | 2021.09.07 |
---|---|
124 나라의 숫자 (자바) (0) | 2021.09.06 |
단체사진찍기 (0) | 2021.09.04 |
카카오 프렌즈 컬러링북 (0) | 2021.09.03 |
직업군 추천하기 (0) | 2021.09.03 |