문제) 백준 - 수학 - 소수 최소 공배수
https://www.acmicpc.net/problem/21919
21919번: 소수 최소 공배수
수열 중에 소수는 2, 3, 5가 있다.
www.acmicpc.net
N개의 숫자 배열 A를 입력받아 각 숫자의 소수 판별 후 최소 공배수를 구하면 해결할 수 있었습니다.
C++ 소스코드)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int A[MAX]; | |
bool isPrime[PRIMEMAX]; | |
void prime(){ | |
isPrime[2] = true; | |
for(int i = 2; i < sqrt(PRIMEMAX); ++i) | |
if(isPrime[i]) | |
for(int j = i * i; j < PRIMEMAX; j += i) | |
isPrime[j] = false; | |
} | |
// 6 8 | |
int LCA(int a, int b){ | |
if(b % a == 0) return a; | |
return LCA(b % a, a); | |
} |
Full Code)
GitHub - Chocochip101/BOJ_Solution: BOJ Solutions
BOJ Solutions. Contribute to Chocochip101/BOJ_Solution development by creating an account on GitHub.
github.com
반응형
'PS(Problem Solving) > 백준_BOJ' 카테고리의 다른 글
[백준] 6118번 - 숨바꼭질 (C++) 문제 및 풀이 (0) | 2022.02.19 |
---|---|
[백준] 2302번 - 극장 좌석 (C++) 문제 및 풀이 (0) | 2022.02.18 |
[백준] 21610번 - 마법사 상어와 비바라기 (C++) 문제 및 풀이 (0) | 2022.02.17 |
[백준] 14712번 - 넴모넴모 (Easy) (C++) 문제 및 풀이 (0) | 2022.02.17 |
[백준] 2167번 - 2차원 배열의 합 (C++) 문제 및 풀이 (0) | 2022.02.17 |
댓글