본문 바로가기

Algorithm

백준(baekjoon)(BaekJoon)코딩 1978번:소수찾기 답

반응형
 
 
#include <iostream>
using namespace std;
int main() {
    int num, cnt =0, total = 0;
    cin >> num;
    int *arr = new int[num];
    for (int i = 0; i < num; i++){
        cin >> arr[i]; 
    }
    for (int i = 0; i < num; i++){
        for (int j = 1; j <= arr[i]; j++){
            if (arr[i] % j == 0){
                cnt++;
            }
        }
        arr[i] = cnt;
        cnt = 0;
    }
    for (int i = 0; i < num; i++){
      if (arr[i] == 2){
	      total++;
      }
    }
    cout << total;
}