🔗문제 풀러가기
단계별로 풀어보기 단계 9의 4번째 문제이다.
소수를 어떻게 판별할지만 생각해낼 수 있다면 쉽게 풀 수 있다.
#include <iostream>
using namespace std;
int main()
{
int inputCnt;
cin >> inputCnt;
int cnt = 0;
for (int i = 0; i < inputCnt; i++)
{
int input;
cin >> input;
bool isprime = true;
if (input == 1) { continue; }
for (int j = 1; j < input; j++)
{
if (input % j == 0 && j != 1 && j != input)
{
isprime = false;
}
}
if (isprime) { cnt++; }
}
cout << cnt;
}