fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. bool primeNumber(int num) {
  6. float root = sqrt(num);
  7. if (num <= 1) {
  8. return false;
  9. }
  10. else if (num == 2 || num == 3) {
  11. return true;
  12. }
  13. else {
  14. for (int i = 2; i <= root; i++) {
  15. if (num % i == 0) {
  16. return false;
  17. }
  18. else
  19. return true;
  20. }
  21. }
  22.  
  23. }
  24.  
  25.  
  26. int main() {
  27.  
  28. int num, inputNum, count = 0;
  29. cin >> num;
  30.  
  31. for (int i = 0; i < num; i++) {
  32. cin >> inputNum;
  33. if (primeNumber(inputNum)) {
  34. count++;
  35. }
  36. }
  37. cout << count;
  38. }
Success #stdin #stdout 0.01s 5476KB
stdin
1
9
stdout
1