-
[백준] 2581 소수 c++STUDY/C++, C#, VB6, PYTHON 2023. 3. 27. 22:56
https://www.acmicpc.net/problem/2581
#include <iostream> #include <algorithm> #include <vector> #include <array> #include <cmath> #include <functional> #include <string> #include <sstream> #include <numeric> #include <stack> using namespace std; void fastIO(); int main() { int M, N = 0; int cnt = 0; vector<int> vec; cin >> M; cin >> N; for (auto i = M; i <= N; i++) { for (auto j = 1; j <= i; j++) { if (i % j == 0) cnt++; } if (cnt == 2) { vec.push_back(i); } cnt = 0; } if (vec.empty()) { cout << "-1" << endl; } else { cout << accumulate(vec.begin(), vec.end(), 0) << endl; cout << *min_element(vec.begin(), vec.end()) << endl; } } void fastIO() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
'STUDY > C++, C#, VB6, PYTHON' 카테고리의 다른 글
[백준] 2587 c++ 대표값2 (0) 2023.03.14 [백준] 2798 c++ 블랙잭 (0) 2022.08.25 [백준] 2869 c++ 달팽이는 올라가고 싶다 (0) 2022.08.25 [백준] 1316 c++ 그룹 단어 체커 (0) 2022.08.25 [백준] 25304 c++ 영수증 (0) 2022.08.24