Count of composite integers in an array

mail@pastecode.io avatar
unknown
c_cpp
6 months ago
448 B
3
Indexable
Never
#include <iostream>
#include <vector>

bool isPrime(int n)
{
	for (int i = 2; i * i <= n; ++i)
		if (n % i == 0)
			return false;
	return true;
}

int main()
{
 
	std::vector<int> x;
	int n, input;
	std::cin >> n;
	
	for (int i = 0; i < n; ++i)
	{
		std::cin >> input;
		x.push_back(input);
	}

	int q = 0;

	for (int i = 0; i < x.size(); ++i)
		if (x[i] > 1 && !isPrime(x[i]))
			++q;

	std::cout << q;
	return 0;
}