Blame view

P50095_en/S001-AC.cc 512 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
#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;
	while(cin >> a)
	{
		if(isPrime(a))
		{
			while(!isPrime(++a)) {}
			cout << a << endl;
		}
		else
		{
			return 0;
		}
	}
}