์ค๋ฒ4 : ์ํ ๋ฌธ์ ์ด๋ค. ์๊ฐ ์์ ๊ตฌํ๋ ์๊ณ ๋ฆฌ์ฆ์ธ ์๋ผํ ์คํ ๋ค์ค์ ์ฒด๋ฅผ ์ฌ์ฉํ๋ฉด ๊ฐ๋จํ ํ ์ ์๋ค. Code #include<iostream> #include<vector> #include<string> #include<cstring> #include<cmath> #include<algorithm> #define MAX 10000 using namespace std; int N, M; bool isPrime[MAX+1]; void SeiveofEratosThenes(){ fill(isPrime+2, isPrime+MAX+1, true); for (int i = 2; i*i <= M; i++) { if (isPrime[i] == false) continue; for (int j = i*i; j <= M; j+=i) { isPrime[j] = false; } } } int main(){ cin >> N >> M; SeiveofEratosThenes(); vector<int> primeArr; int sum = 0; for (int i = N; i <= M; i++) { if (isPrime[i]) { primeArr.push_back(i); sum += i; } } if (primeArr.size() == 0) { cout << -1 << '\n'; } else cout << sum << '\n' << primeArr[0] << '\n'; return 0; } Reference ๋ฐฑ์ค(2581๋ฒ) - ์์