Blame view

P48713_en/S005-AC.cc 573 Bytes
Imanol-Mikel Barba Sabariego authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <cmath>

using namespace std;

bool isPrime(int a)
{
	if(a == 2 || a == 3 || a == 5)
	{
		return true;
	}
	if(a == 1)
	{
		return false;
	}
	if(a%2)
	{
		if(a%3)
		{
			if(a%5)
			{
				for(int i = 2; i < (sqrt(a)+1); i++)
				{
					if(!(a%i))
					{
						return false;
					}
				}
				return true;
			}
		}
	}
	return false;
}


int main()
{
	int a,b;
	cin >> a;
	for(int i = 0; i < a; i++)
	{
		cin >> b;
		if(isPrime(b))
		{
			cout << b << " is prime" << endl;
		}
		else
		{
			cout << b << " is not prime" << endl;
		}
	}
	return 0;
}