일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- SQL
- mariaDB
- 알고리즘
- mybatis
- DP
- 정렬
- 데이터베이스
- db
- BFS
- 백준
- 이펙티브자바
- join
- IntelliJ
- java
- 그리디알고리즘
- Database
- springboot
- 너비우선탐색
- 깊이우선탐색
- DFS
- 우선순위큐
- Spring
- 탐욕법
- 피보나치
- Effective Java
- 프로그래머스
- select
- Greedy
- 다이나믹프로그래밍
- 코테
Archives
- Today
- Total
땀두 블로그
[백준] 2609번 - 최대공약수와 최소공배수 본문

import java.util.Scanner;
public class p2609 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = a * b;
while (b != 0) {
int r = a % b;
a = b;
b = r;
}
System.out.println(a);
System.out.println(c/a);
}
}
모듈러 연산을 통해서 간단하게 최대공약수를 구한 뒤 a, b의 곱에서 최소공배수를 나누어주어 최소공배수를 구한다.
'알고리즘 > 백준' 카테고리의 다른 글
[백준] 10814번 - 나이순 정렬 (0) | 2022.03.19 |
---|---|
[백준] 1978번 - 소수 찾기 (0) | 2022.03.19 |
[백준] 10989번 - 수 정렬하기 3 (0) | 2022.03.19 |
[백준] 2751번 - 수 정렬하기 2 (0) | 2022.03.19 |
[백준] 2750번 - 수 정렬하기 (0) | 2022.03.19 |
Comments