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

21.03.25 - [BOJ] 2609. 최대공약수와 최소공배수 #45

Closed
suhyunsim opened this issue Mar 27, 2021 · 0 comments
Closed

21.03.25 - [BOJ] 2609. 최대공약수와 최소공배수 #45

suhyunsim opened this issue Mar 27, 2021 · 0 comments
Assignees
Labels
성공 맞은 문제 수학 수학 실버 BOJ - 실버

Comments

@suhyunsim
Copy link
Owner

문제

핵심 아이디어

  • GCD = g, LCM = l
  • g: a % b를 계속해서 b에 나눠서 나머지가 0 이되는 값 (유클리드 호제법 이용)
  • l: g * (a / g) * (b / g) = (a * b) / g

어려운 점, 실수

풀이

package main.java.com.poogle.BOJ.Q2609;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int g = gcd(a, b);
        int l = (a * b) / g;
        System.out.println(g);
        System.out.println(l);
        sc.close();
    }

    private static int gcd(int x, int y) {
        if (y == 0) {
            return x;
        } else {
            return gcd(y, x % y);
        }
    }
}
@suhyunsim suhyunsim added 성공 맞은 문제 수학 수학 실버 BOJ - 실버 labels Mar 27, 2021
@suhyunsim suhyunsim added this to the 3월 4주 차 milestone Mar 27, 2021
@suhyunsim suhyunsim self-assigned this Mar 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
성공 맞은 문제 수학 수학 실버 BOJ - 실버
Projects
None yet
Development

No branches or pull requests

1 participant