Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 오일러 경로
- spring boot
- dag
- dfs
- 확률
- 이분탐색
- 확률변수
- BFS
- 표본 추출
- 인터페이스
- 다형성
- 확률분포
- 알고리즘
- 베이지안
- 재설치
- Random variable
- 너비 우선 탐색
- 이진탐색
- divide and conquer
- 분할정복
- 기술 통계
- Solid
- 추론 통계
- Probability Distribution Function
- PostgreSQL
- 깊이 우선 탐색
- 객체 지향 설계
- 확률분포함수
- Algorithm
- 스프링
Archives
- Today
- Total
말하는 감자
[Algorithm] 최대공약수, 최소공배수 알고리즘 본문
728x90
최대공약수 구하기 - 유클리드 호제
public int gcd(int a, int b){
int x = Math.max(a, b);
int y = Math.min(a, b);
if(y==0) return x;
else return gcd(y, x%y);
}
최소공배수 구하기
public int lcm(int a, int b){
int gcd = gcd(a, b);
return a * b / gcd;
}
'Computer science & Infra > DSA' 카테고리의 다른 글
[Alogrithm] 소수인지 판별하기 (0) | 2023.04.21 |
---|---|
[Graph] MST / 최소 스패닝 트리 / 최소 신장 트리 (0) | 2023.04.13 |
[Graph] BFS 그래프 너비 우선 탐색과 최단 거리 (0) | 2023.02.22 |
[Divide and Conquer] 이진 탐색 알고리즘 (0) | 2023.02.22 |
[Graph] DFS의 대표 예시 오일러 경로 (1) | 2023.01.31 |
Comments