Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22.01.04 - [PG] 멀쩡한 사각형 #181

Closed
suhyunsim opened this issue Jan 4, 2022 · 0 comments
Closed

22.01.04 - [PG] 멀쩡한 사각형 #181

suhyunsim opened this issue Jan 4, 2022 · 0 comments
Assignees
Labels
lv.2 프로그래머스 - level 2 성공 맞은 문제 수학 수학

Comments

@suhyunsim
Copy link
Owner

문제

핵심 아이디어

  • 최대공약수 활용
  • long 고려

어려운 점, 실수

풀이

package main.java.com.poogle.PG.Q62048;

public class Solution {

    public static void main(String[] args) {
        System.out.println(solution(8, 12));
    }

    private static long solution(int w, int h) {
        long sum = (long) w * (long) h;
        long not = 0;
        long gcd = calGCD(w, h);
        if (gcd == 1) {
            not = w + h - 1;
        } else if (gcd > 1) {
            not = gcd * ((w / gcd) + (h / gcd) - 1);
        }
        return sum - not;
    }

    private static long calGCD(long a, long b) {
        if (a % b == 0) {
            return b;
        }
        return calGCD(b, a % b);
    }

}
@suhyunsim suhyunsim added 성공 맞은 문제 수학 수학 lv.2 프로그래머스 - level 2 labels Jan 4, 2022
@suhyunsim suhyunsim added this to the 1월 1주 차 milestone Jan 4, 2022
@suhyunsim suhyunsim self-assigned this Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lv.2 프로그래머스 - level 2 성공 맞은 문제 수학 수학
Projects
None yet
Development

No branches or pull requests

1 participant