슈콩

[BOJ] 백준 5347 LCM 본문

Algorithms/Baekjoon

[BOJ] 백준 5347 LCM

shukong 2025. 9. 15. 22:31

[문제]

https://www.acmicpc.net/problem/5347

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		int t = Integer.parseInt(br.readLine());
		while(t-->0) {
			st = new StringTokenizer(br.readLine());
			long a = Long.parseLong(st.nextToken());
			long b = Long.parseLong(st.nextToken());
			System.out.println(LCM(a,b));
		}
	}
	private static long LCM(long a,long b) {
		long cpA = a;
		long cpB = b;
		while(cpA != 0) {
			long tmpA = cpA;
			cpA = cpB%cpA;
			cpB = tmpA;
		}
		return a / cpB * b;
	}
}

'Algorithms > Baekjoon' 카테고리의 다른 글

[BOJ] 백준 9020 골드바흐의 추측  (0) 2025.09.15
[BOJ] 백준 6359 만취한 상범  (0) 2025.09.15
[BOJ] 백준 3343 장미  (0) 2025.09.15
[BOJ] 백준 3343 캠핑  (0) 2025.09.15
[BOJ] 백준 3343 장미  (0) 2025.09.15