algorithm

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub gtnao/algorithm

:heavy_check_mark: test/aoj/alds1_1_c.test.cpp

Depends on

Code

#define PROBLEM                                                                \
  "https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/1/ALDS1_1_C"

#include <bits/stdc++.h>
using namespace std;

#include "../../src/math/is_prime.hpp"

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (is_prime(a)) {
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}
#line 1 "test/aoj/alds1_1_c.test.cpp"
#define PROBLEM                                                                \
  "https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/1/ALDS1_1_C"

#include <bits/stdc++.h>
using namespace std;

#line 2 "src/math/is_prime.hpp"

#line 4 "src/math/is_prime.hpp"
using namespace std;

template <typename T = long long> bool is_prime(T n) {
  for (T i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
#line 8 "test/aoj/alds1_1_c.test.cpp"

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (is_prime(a)) {
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}
Back to top page