백준 13241 (최대 공약수)

김경욱·2025년 8월 14일

백준

목록 보기
43/121

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st = new StringTokenizer(br.readLine());

        long a = Integer.parseInt(st.nextToken());
        long b = Integer.parseInt(st.nextToken());

        long gg =  gcd(a, b);

        long result = (a*b/gg);

        System.out.println(result);



}

    public static long gcd(long a, long b)  // 18 ,24
    {
        while(b!=0)
        {
            long temp = b;  // temp = 24   temp = 18  temp = 6
            b = a % b;  // b = 18     b = 6     b = 0
            a = temp; // a = 24     a  =  18   a = 6
        }

        return a;
    }



}

이전에 푼 문제에서 int를 long으로만 바꾸면 되는 문제였다..

0개의 댓글