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 | 31 |
Tags
- Programmers
- 주식 용어 정리
- 2370 c++
- 백준 2370
- 백트레킹
- MySQL
- 브루트포스
- 백준 1697
- 삼성 SW역량 테스트
- 백준 알고리즘
- 15651
- DP
- 프로그래머스
- 위상정렬
- 삼성 SW 역량 테스트 기출 문제
- fill함수
- 주린이
- 주식 용어
- BFS
- 백준
- 백준 15651
- 백준알고리즘
- 15651c++
- backtracking
- DFS
- C++
- 시장 선거 포스터 c++
- 용어 정리
- 에라토스테네스의 체
- 삼성SW 역량 테스트 기출문제
Archives
- Today
- Total
빠켱이
프로그래머스 N개의 최소공배수[C++] 본문
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int gcd(int a, int b){
int r = 1;
while(r > 0){
r = b % a;
b = a;
a = r;
}
return b;
}
int solution(vector<int> arr) {
int answer = arr[0];
sort(arr.begin(), arr.end());
for(int i = 1; i < arr.size(); i++){
int tmp = gcd(answer, arr[i]);
answer = answer * arr[i] / tmp;
}
return answer;
}
'알고리즘 > 프로그래머스 알고리즘' 카테고리의 다른 글
프로그래머스 행렬의 곱셈[C++] (0) | 2021.05.05 |
---|---|
JadenCase 문자열 만들기[C++] (0) | 2021.05.05 |
프로그래머스 짝지어 제거하기[C++] (0) | 2021.05.05 |
프로그래머스 큰 수 만들기[C++] (0) | 2021.05.04 |
프로그래머스 단체사진 찍기[C++] - 2017 카카오코드 본선 (0) | 2021.05.04 |
Comments