library

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

View the Project on GitHub yuruhi/library

:heavy_check_mark: test/isPrime.test.cpp

Depends on

Code

#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_1_C"
#include "./../math/isPrime.cpp"
#include <iostream>
using namespace std;

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	int ans = 0;
	while (n--) {
		int x;
		cin >> x;
		ans += isPrime(x);
	}
	cout << ans << '\n';
}
#line 1 "test/isPrime.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_1_C"
#line 2 "math/isPrime.cpp"

template <class T> bool isPrime(T n) {
	if (n == 2) return true;
	if (n < 2 || n % 2 == 0) return false;
	for (T i = 3; i * i <= n; i += 2) {
		if (n % i == 0) return false;
	}
	return true;
}
#line 3 "test/isPrime.test.cpp"
#include <iostream>
using namespace std;

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	int ans = 0;
	while (n--) {
		int x;
		cin >> x;
		ans += isPrime(x);
	}
	cout << ans << '\n';
}
Back to top page