백준 2581번: 소수

Se0ng_1l·2022년 6월 23일
0

백준

목록 보기
7/40

1978번의 응용문제
https://www.acmicpc.net/problem/2581

#include <iostream>
using namespace std;

int main()
{
    int num1 = 0;
    int num2 = 0;
    cin >> num1 >> num2;
    int *arr = new int[num2 - num1 + 1];

    int min;
    bool chk = false;
    int result = 0;

    for(int i = num1; i <= num2; i++)
    {
        int cnt = 0;
        for(int j = 1; j <= i; j++)
        {
            if(i % j == 0)
            {
                cnt++;
            }
        }
        if(cnt == 2)
        {
            if(!chk)
            {
                min = i;
                chk = true;
            }
            result += i;
        }

    }
    if(result == 0)
        cout << -1;
    else
        cout << result << endl << min;
    delete [] arr;
}
profile
치타가 되고 싶은 취준생

0개의 댓글